Look at the complex paging SQL statements generated by Entity Framework 4.

Source: Internet
Author: User

Previously, the COUNT query statement generated by Entity Framework 4 was found, and the paging SQL statement generated by Entity Framework 4 was found today, but this problem does not exist in LINQ to SQL.

>>> Let's take a look!

Code:

Check the generated SQL statement:

1. SQL statement generated by Entity Framework:

One TOP, three FROM.

2. the SQL statements generated by LINQ to SQL:

No TOP, two FROM.

The gap between the two is clear at a glance.

>>> Let's take a look at the following:

Change the Where query condition in the code above to a constant, that is, Where (coder => coder. Age> 20). For details, see:

Then look at the generated SQL.

1. SQL statement generated by Entity Framework:

It is obviously different (color). In fact, only exec sp_executesql is missing, but it will affect the performance (sp_executesql will use cached plan to get more performance, which is mentioned here ).

2. the SQL statements generated by LINQ to SQL are the same as those before.

 

Entity Framework considers multi-database support and stored procedure support, but ignores this.

FromDataContextTo the Entity FrameworkObjectContextAnd then launch ADO. NET Entity Framework Feature CTP5.DbContextDbContext does not solve this problem, and Microsoft's thinking is a bit messy.

Currently, if Entity Framework 4 is used and performance is concerned, there are only two options: 1. you do not need to write SQL statements or stored procedures without using LINQ to Entities. 2. write your own Entity Framework ADO.. NET provider for SQL Server.

Update: From the execution plan, the SQL statements generated by Entity Framework seem to have no impact on performance.

Supplement:

Comparison of execution plans of two SQL statements:

A) SQL statement generated by Entity Framework:

B) the SQL statements generated by LINQ to SQL:

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.