Look at the complex page-Entity SQL statements generated by the Framework 4

Source: Internet
Author: User
Keywords Statements pagination complexity this
Tags code framework pagination paging sql statement sql statements

The count query statement generated by entity Framework 4 was previously found to be a problem with the paging SQL statement that it generated today, and LINQ to SQL does not.

>>> take a look, and see!

Code on:

Look at the generated SQL statement:

1. SQL generated by the Entity framework:

A top, three from.

2. LINQ to SQL generated sql:

No top, two from.

The gap between the two is clear.

>>> look at one more:

Change the query condition of the Where in the code above to a constant, where coder => coder. Age > 20), see figure below:

Then look at the generated SQL.

1. SQL generated by the Entity framework:

It's obviously not the same (color), but it's actually just a few exec sp_executesql, but it's going to have a performance impact (sp_executesql will-use cached-get-more configured, here's the problem).

2. LINQ to SQL generates the same SQL as before.

The Entity framework takes into account multiple database support, stored procedure support, but ignores this place.

From the DataContext of LINQ to SQL to the ObjectContext of the Entity framework, and then the Ado.net Entity framework Feature CTP5, DbContext also did not solve the problem, feeling that Microsoft's thinking a bit messy.

Now it seems that if you use the Entity Framework 4 and care about performance, there are only two choices: 1. Write your own SQL or stored procedure without LINQ to Datastore; 2. Write your own entity Framework ado.net provider for SQL Server.

Update: From the execution plan, the SQL generated by the Entity framework appears to have little impact on performance.

Added:

Two SQL execution plan comparisons:

A Entity framework-generated SQL:

b The SQL generated by LINQ to SQL:

Related Article

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.