How to use Entity Framework with Stored procedures and POCOs

I am trying here to use Entity Framework with Stored procedures and POCOS and 2 different projects.

I have one project DataAccess (for my edmx and DataContexts) and one project BusinessEntities (for my POCOs). DataAccess have a reference of BusinessEntities.

In my DB I have a pretty standard SP :

    @id CHAR(35)
    SELECT ID, Name FROM mytable WHERE ID = @id

The datacontext is :

public class DbContext : ObjectContext
public ObjectResult<BusinessEntities.GetHeaderResult> GetHeader(string id)
return base.ExecuteFunction<BusinessEntities.GetHeaderResult>("GetHeader", new ObjectParameter("id", id));

If I only go like this (the EDMX has been updated with the SP but the function has not been imported) I have this error :

System.InvalidOperationException: The FunctionImport &#39;GetHeader&#39; could not be found in the container &#39;DbEntities&#39;.

If I import the function correctly I have this error :

System.InvalidOperationException: The type parameter 'BusinessEntites.GetHeaderResult' in ExecuteFunction is incompatible with the type 'DbModel.GetHeaderResult' returned by the function.

I guess that it is only just a simple setting that is missing here but I can't seem to grab it.

Please not that the EDMX file has the correct setting (CodeGenerationStrategy set to none, CustomTool is empty)


In the first case you are calling wrong method on the context. ExecuteFunction is only for function imports. Use ExecuteStoreQuery and SqlParameter instead. In the second case function import also creates a complex type in your EDMX and EF expects you will use that complex type as a result of function import call.

Need Your Help

Image Cropping using Predefined ROI Matlab

image matlab crop roi

Basically what I'm trying to do is using predefined ROI's to crop and image into multiple new images.

jquery sortable table rows - rows change height after sorting

jquery jquery-ui table sortable jquery-ui-sortable

I'm trying to use jQuery UI sortable on a table, and am experiencing a problem. Once i drop a row the height is not exactly what it was before. It gets smaller and the rows don't use up the whole t...