Page 1 of 1

Function Import missing from ObjectContext

Posted: Fri 20 Jun 2008 03:00
by jdaly
According to the ADO.NET Entity Framework I should be able to invoke a stored proc via the ObjectContext. I have followed the steps of including a sproc in my entity model and creating a function import for it, but I cannot see a method on my ObjectContext class to enable me to invoke the sproc in code. Am I missing something? How am I supposed to call the sproc once I have included it in the entity model?

Posted: Mon 23 Jun 2008 11:52
by Alexey.mdr
Hello,

using stored procedure in OraDirect .NET and Oracle server is the same as with MS SQL server.
As soon as you generated the edmx file (with SP) open it in Model Browser.
Then perform the following steps:
- select a table that you want to update with a SP
- click on Mapping Details window (View -> Other Windows -> Mapping Details)
- in the top left corner of the window click on the bottom picture (Map Entity to Functions)
- select the needed function, in my case "Insert Using DEPT_INSERT"
- map the SP parameters to the table columns

That's all. Then you simply call an AddTo*** method and save the changes.

Regards,
Alexey.

Posted: Tue 24 Jun 2008 03:43
by jdaly
Thanks Alexey, very helpful.

I also am trying to work out how to invoke a sproc via the ObjectContext which just does a SELECT, and can't figure that out. Is there a way?

The reason I want to do this is to invoke a sproc which returns the result from a call to GetNextID on an oracle sequence, to use to populate a primary key property on a new object prior to calling save on the context.

And the reason I want to do that is because our DBA is nervous about us using triggers on inserts to populate primary keys on the table.

I was expecting to be able to write code like this:

Code: Select all

using(MyObjectContext ctx = new MyObjectContext())
  long ID = ctx.GetNextID();
where "GetNextID" is mapped to a sproc.

Posted: Tue 24 Jun 2008 15:12
by Alexey.mdr
Hello,

We investigated the problem.
Well, currently this feature (Function Import) is not properly implemented in EDM designer.
We are looking for a solution.
This may take some time.
Probably we will wait for the EF release.

Regards,
Alexey.

Function Import missing from ObjectContext

Posted: Tue 10 Feb 2009 21:21
by Anchor
Can someone tell me where we are with this topic?

I am trying to do something similar. I want to call a stored procedure that takes a couple of strings but have it just return an integer or a collection of integers.

When I try to add the stored procedure, through the Function Import, I cannot add this stored procedure to my context. Is there a software patch or a work-around?

Posted: Wed 11 Feb 2009 13:04
by AndreyR
Microsoft supports Function Imports only for Stored Procedures returning result set.
There is no way to create Function Import for the procedure you described using ADO.NET Entity Data Model Designer.
But we are working on a tool which will give an opportunity to solve this and many other problems.

Posted: Tue 23 Jun 2009 15:08
by Anchor
I know I am a little late of this topic but I just wanted to comfirm something.

When you say "Microsoft supports Function Imports only for Stored Procedures returning result set" you mean the Visual Studio IDE/Entity Framework does not support "function imports" returning nothing or scalar types, only Entities. So even though VS 2008 allows you to select "None" or "Scalar Type" for a return type when creating a function import, the entity framework does not support it. Correct?

Posted: Wed 24 Jun 2009 06:48
by AndreyR
Correct.
The Microsoft code generation does not support Function Imports that do not return resultset.
You can try Devart Entity Developer, our code generation provides such support.

Posted: Wed 24 Jun 2009 13:16
by Anchor
Yes. A co-worker here downloaded it and I was surprise to see it that it worked and not Microsoft's EDM IDE. (I guess I shouldn't have been surprise. ;-) )

I might use your Entity Developer in the future given that Microsoft's next release might not be for a while. However, what do I do if I have a EDM developed using Microsoft's IDE? Will your Entity Developer work with a Microsoft .edmx file?

Posted: Wed 24 Jun 2009 13:50
by AndreyR
You can open an .edmx file using Entity Developer and save it as an .edml file.