Sykomaniac Sykomaniac - 1 year ago 142
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download