I certainly have not yet explored the depths of EF4 to the same extent as I have with the current version and I have a lot of discoveries ahead of me.
Thanks to a tweet this morning by Zekq, I finally saw one of the promised improvements to EF’s stored procedure support.
In EF v1, you can easily create a function based on a stored procedure through function mapping for stored procs that return scalars. But calling those functions is not as easy. The code generator does not create a class method for the function. The only way to execute these functions is through EntityClient. You can easily find examples of this on the web or if you have my book, Programming Entity Framework, there is an example in VB and C# at the beginning of Chapter 13.
Now in EF4, the default code generator does indeed create the function so that it is now simple to call the function in your code without spinning up and executing an EntityConnection and EntityCommand.
If you haven’t mapped functions before, here is a quick walkthrough:
When you import a stored proc with teh EDM Wizard (or Update Wizard), the procedure gets inserted into the store schema (SSDL) but not into your conceptual model.
You need to map the procedure to your CSLD using a Function Import.
Step 1: Right click on the function in the model browser and choose Add Function Import.
Step 2: Define the Function Import. Here I have indicated that the function returns an Int32 result.
Now the function is part of your CSDL. You will not see it in the designer but you will see it in the raw XML and the Model Browser.
So far this is exactly the same as EFv1. The difference is that the code generator has add the function to the EFWorkshopEntities class and I can easily call it in my code now as I would any other function.




