问题
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