繁体   English   中英

如何使用 LINQ 和 EntityFramework 实现连接

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM