由此能够看出其最终都转移成Command Tree 而后再转换成对应数据库的T-SQL语句,本质差异不大,可是有时执行特殊查询语句的时候仍是有点不同的,由于Entity SQL的T-SQL语句是咱们本身定义的,而LINQ to Entity最后转换的T-SQL语句是由Entity引擎转换的,有时咱们用SQL Server Profiler检测执行的SQL语句的时候LINQ to Entity执行的SQL每每让咱们不容易理解,因此在须要对某些查询/修改/更新执行操做的时候若是发现执行效率不高的话能够考虑使用Entity SQL自定义执行SQL语句,下边贴出点代码:数据库
1.LINQ TO Entityc#
string city = "London"; using (Entities entities = new Entities()) { var query = from c in entities.Customers where c.Address.City == city select c; foreach (Customers c in query) Console.WriteLine(c.CompanyName); }
2.Entity SQL(注意SQL语句哦)ide
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); }