Function Import missing from ObjectContext
Function Import missing from ObjectContext
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?
-
- Posts: 729
- Joined: Thu 13 Dec 2007 10:24
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.
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.
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:
where "GetNextID" is mapped to a sproc.
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();
-
- Posts: 729
- Joined: Thu 13 Dec 2007 10:24
Function Import missing from ObjectContext
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?
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?
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?
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?
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?
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?