Use EntityFramework 5.0 for Stored procedures (& Execute SQL, performance optimization)

Source: Internet
Author: User

EntityFrameWork5.0 simple to use

Profile:

Use EntityFrameWork5.0 to execute stored procedures, SQL statements (DDL/DML), and a little bit about optimizing performance;

Body:

A stored procedure (select) that needs to present the data is included under MYEF.TT


The Model browser is as follows


1.EF How to call a stored procedure:

Note: The entity for the database table, expressed as a class object, can be manipulated directly under the EF container, such as db. UserAccount directly to UserAccount entity objects, stored procedures, views are the same, but also can be obtained through the EF context container;

2.EF Execute SQL statement:

Note: In two cases, a query SQL, a non-query SQL, is defined in the context container under the database object, where the Sqlquery<t> () method supports generics;

3.EF Performance Optimization

<1> delayed loading and caching mechanisms

It is generally tolist () to execute SQL, usually by where (), Count (), any (), and so on, to generate the SQL statement, run to the call to execute SQL (or Manual tolist ());

In addition, under the same context container, if the query data is repeated, there will be a caching mechanism to optimize, not send SQL to execute again, but from the cache directly reuse;

<2> do not track queries

When we query the data, the context container will identify the state of the data as unchanged for management, if the next and need to save changes to the data query to delete operations, you can use the non-tracking query, so that the context container no longer tracking query data to improve performance;

4. Programming for Stored procedures

end!

Use EntityFramework 5.0 for Stored procedures (& Execute SQL, performance optimization)

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.