Left Join in Entity Framework 3.5

£可爱£侵袭症+ 提交于 2020-01-13 03:36:09

问题


I am trying to left join on entity frame work 3.5 but i am unable to do so...

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?


回答1:


You need to use DefaultIfEmpty() for an outer join:

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.




回答2:


You will find examples of different LINQ joins here: http://code.msdn.microsoft.com/LINQ-Join-Operators-dabef4e9 and loads of other LINQ examples too.




回答3:


Entity framework in .NET 3.5 doesn't offer left join in Linq queries. The way to get "joined records" is through navigation property between entities

From here: Left Outer Join in Entity Data Model asp.net



来源:https://stackoverflow.com/questions/8415581/left-join-in-entity-framework-3-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!