[英]how to implement join using LINQ and EntityFramework
我正在嘗試在 EF 4.0 查詢中創建一個 linq 2 sql,如下 sql 查詢。
SELECT * FROM Role
LEFT JOIN Queue
ON Role.RoleId = Queue.RoleId
WHERE QueueId = 361
那么我怎么能在 EF 4.0 中做到這一點呢?
通常這是使用在您獲取實體時加載的導航屬性來完成的,但是您也可以通過以下方式執行此操作:
from r in Roles
from q in Queues
where r.RoleId == q.RoleId
where q.QueueId == 361
select new { r.RoleId, q.QueueId /*other bits you want*/}
嘗試以下方法,希望對您有所幫助
我建議搜索更多關於連接的信息
var result=(from p in Roles
join pa in Queue on p.RoleId equals pa.RoleId into temproles
from addresses in temproles.DefaultIfEmpty() where temproles.queueId = 361
select new { p, pa} );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.