由此能夠看出其最終都轉移成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); }