www.allpaul.com

I needed somewhere to put all this crap
Welcome to www.allpaul.com Sign in | Help
in Search

Programming

Entity Framework Stored Procedure Gotcha

I recently discovered and interesting tidbit about stored procedures and their counterparts, function imports, in the entity framework (EF).  In the past I have used stored procedures in the EF when I need to do complex operations when adding new database records. The one thing I never really paid attention to was the return type of the stored procedure.  I'll generally add a select * from the  corresponding table and return all the values of the newly added row.  Then in the EF model designer, I create a function import and set the return type to the type of object just added. 

I needed to return a scalar value (int) from a stored procedure and that's where the gotcha comes in.

It seems that the object context (OC) of an EF model doesn't handle scalar return types.  The model designer allows you to create the function import and set the return type to a scalar value, however the model will not have any reference to the new method (via intellisense or at runtime).

I found a few posts discussing the issue which seems to be fixed in the next version of the EF...Here are a few links

http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/4fae55c8-e103-46a8-b4c3-16077e912bf9

http://www.danrigsby.com/blog/index.php/2009/05/20/entity-framework-40-scalar-and-void-functions/

For now I am going to use the method in the first link.  I'll create a function that encapsulate some database code and replace it later when the next version of the EF is out.

Only published comments... Jun 10 2009, 06:28 AM by paully21

Comments

 

Sanaa RAMZI said:

Hello,

This is helpful. I appreciate your way of exposing the problem, this is exactly what I'm facing, I'm sure I'm not the only one...

I wanna use the code in the first post too, but I don't know exactly how to call the entity contructor with the connectionstring. I posted my issue but got no answer for now, and I need to move on with this asap :)

Would you be kind and tell me what to pass in the connectionstring parameter ? Connection.ConnectionString doesn't seem to work for me and I don't know where to bring it from, or how to grab the connectionstring from app.config.

I'm working on a windows application...

Thanks in advance.

Regards,

Sanaa RAMZI

July 24, 2009 10:27 AM
 

Waleed said:

October 21, 2009 4:34 PM
 

GPS Tracking Systems said:

This will be pretty useful for many people who are working as IT professionals, looking forward for some more creative work from your end. :)  

March 3, 2010 12:50 AM

Leave a Comment

(required) 
(optional)
(required) 
Submit

About paully21

 

Powered by Community Server (Non-Commercial Edition), by Telligent Systems