Essential differences between Entity SQL and LINQ TO Entity

Source: Internet
Author: User

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/200P5CQ-0.png "title =" 060309_0406_EntityFram11.png "/>

It can be seen that the final are transferred to the Command Tree and then converted to the corresponding database T-SQL statement, the essence of the difference is not big, but sometimes when the execution of special query statements is a bit different, because the T-SQL Statement of Entity SQL is defined by ourselves, while the T-SQL statement of the final conversion of LINQ to Entity is converted by the Entity engine, sometimes, when we use SQL Server Profiler to detect executed SQL statements, the SQL statements executed by LINQ to Entity are often hard to understand, therefore, when you need to perform operations on some queries, modifications, and updates, if you find that the execution efficiency is not high, you can use Entity SQL to customize the execution of SQL statements. below is the code:

1. linq to Entity

string city = "London";using (Entities entities = new Entities()){var query = from c in entities.Customerswhere c.Address.City == cityselect c;foreach (Customers c in query)     Console.WriteLine(c.CompanyName);}

2. Entity SQL pay attention to SQL statements)

string city = "London";using (Entities entities = new Entities()){     ObjectQuery<Customers> query = entities.CreateQuery<Customers>(         "SELECT VALUE c FROM Customers AS c WHERE c.Address.City = @city",new ObjectParameter("city", city));foreach (Customers c in query)     Console.WriteLine(c.CompanyName);}





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.