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