
由此可以看出其最終都轉移成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 Entity
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語句哦)
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);
}免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。