Currently, the EF support for stored procedures is not perfect. The following issues exist:
L EF does not support stored procedures to return the result set of a multiple-table union query.
L EF only supports returning all fields that return a table for conversion to the corresponding entity. The return of a partial field cannot be supported.
L Although a stored procedure that returns a scalar value can be imported normally, the corresponding entity is not automatically generated for us. CS code, we still can't call or use scalar stored procedures directly in code
L EF cannot directly support parameters for output types in stored procedures.
L some other issues.
Here are some details about how to use stored procedures, and how to store some of the fields that return entities and tables.
L Import stored procedures and return entities
In the VS visual designer, open the Entity model (EMDX file). Then, right click on "Customers" à "add" à "function import", then select "Stored Procedure name" and enter the function import name, select return type as entity and select Customers. As shown in the following illustration:
Then, click "OK". After that, the stored procedure is imported. In the code we can use the change stored procedure. As shown in the following code:
[Test]
public void GetEntityBySP()
{
using (var db = new NorthwindEntities())
{
var cst = db.GetCustomerById("ALFKI").FirstOrDefault();
Assert.IsNotNull (cst);
Console.WriteLine("CustomerId:{0},ContactName:{1}", cst.CustomerID, cst.ContactName);
}
}