Utilizing Stored Procedures for Gets

May 7, 2014 at 12:22 PM
Edited May 9, 2014 at 6:50 PM
There is an easy way to map Insert, Update and Delete stored procedures in the Model; what is the best way to map or implement stored procedures for Get?

So, instead of datacontext.Entity.AsQuerable(), how can I use datacontext.GetEntities(params) where GetEntities implements a stored procedure that returns an entityset?

5/9/14 This question has been answered under Issues.
May 17, 2014 at 7:43 PM
For selects you cannot map stored procedures but only tables or views, since stored procedures would restrict the way of querying the data.

If you are looking for a way to expose a stored procedure to a client application using N-Tier Entity Framework you can do the following:
  1. Import the stored procedure via function import into your entity model
  2. Implement a custom service method to invoke the stored procedure (model function) and return the result. This is done best by implementing a partial class and interface:
    ◾partial interface IMyDataService
    ◾partial class MyDataService
  3. Implement a custom method on client data context to forward the call to the web service:
    ◾partial interface IMyDataContext
    ◾partial class MyDataContext
Marked as answer by ChristofSenn on 5/17/2014 at 12:44 PM
May 19, 2014 at 12:46 PM
We have been successful in exposing stored procedures on the client. The Function Import returns an ObjectResult, so we converted that to a QueryResult in a partial repository class. Thank you for your help!