Sykomaniac Sykomaniac - 4 months ago 66
C# Question

EF 6 DataBase First Stored Procedure

When using EF6 Database First and trying to execute a stored procedure the auto-generated context adds the required method but sets the return type as ObjectResult. For example the following definition:

public virtual ObjectResult<USP_GetItemDetails_Result> USP_GetItemDetails(int? itemNbr, int? siteNbr)

Has the return type of:

return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<USP_GetItemDetails_Result>("USP_GetItemDetails", itemNbr, siteNbr);

Is there anyway to materialize this result as just the concrete class rather than having to send the result as ObjectResult? The next layer in my stack is not aware of Entity Framework.


Turns out ObjectResult under the hood is an IEnumerable. A simple toList means I can return an IEnumerable to the next layer.