Entity Framework Learning Intermediate 2-stored procedures (top)

Source: Internet
Author: User
Tags scalar

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);
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.