Entity SQL (ESQL) 是 EF 提供的類 SQL 語言,直接操作概念模型實體,支援繼承、關聯等 EDM 特性。可用於 ObjectQuery 或 EntityClient。
SELECT VALUE c FROM ... 略過隱式 Row 建構,直接回傳實體集合。FROM Customers AS it)。-- 開頭單行註解。@paramName 前綴,於 ObjectParameter 綁定。COUNT(*),改用 COUNT(0)。ORDER BY ... SKIP 0 LIMIT 10(確定性分頁);TOP(10) 為非確定性限制,兩者互斥。CAST(c.Region AS String) 等型別轉換。-- 參數化查詢
SELECT VALUE c FROM NorthwindEntities.Customers AS c WHERE c.CustomerID = @customerID
-- 分頁
SELECT VALUE c FROM NorthwindEntities.Customers AS c ORDER BY c.CustomerID SKIP 0 LIMIT 10
-- TOP
SELECT TOP(10) c.CustomerID FROM NorthwindEntities.Customers AS c ORDER BY c.CustomerID
-- NULL 轉型
SELECT CAST(c.Region AS String) FROM NorthwindEntities.Customers AS c ORDER BY c.CustomerID LIMIT 10
ESQL 為無資料庫相依的查詢語言,適合動態組裝查詢或跨資料庫部署。