简体   繁体   English

左边加入实体框架3.5

[英]Left Join in Entity Framework 3.5

I am trying to left join on entity frame work 3.5 but i am unable to do so... 我试图离开加入实体框架工作3.5但我无法这样做...

from i in
    (from ta in context.test_attempt
     join uf in context.user_flag on ta.users.USERID equals uf.UserID)
select i;

I want to use left join instead to join? 我想用左连接代替加入?

You need to use DefaultIfEmpty() for an outer join: 您需要对外连接使用DefaultIfEmpty()

from ta in context.test_attempt
join uf in context.user_flag on ta.users.USERID equals uf.UserID into g
from uf in g.DefaultIfEmpty()
select new { ta, uf }

Your outer from/select above is unnecessary, just project ta and uf into what you need. 你的外部/上面的选择是不必要的,只需将项目tauf变成你需要的东西。

Entity framework in .NET 3.5 doesn't offer left join in Linq queries. .NET 3.5中的实体框架不提供Linq查询中的左连接。 The way to get "joined records" is through navigation property between entities 获取“联合记录”的方法是通过实体之间的导航属性

From here: Left Outer Join in Entity Data Model asp.net 从这里: 左外部加入实体数据模型asp.net

您可以在这里找到不同LINQ连接的示例: http//code.msdn.microsoft.com/LINQ-Join-Operators-dabef4e9以及其他LINQ示例的加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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