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.