Dewasish Mitruka
Dewasish Mitruka

Reputation: 2896

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...

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?

Upvotes: 4

Views: 3620

Answers (3)

Dherik
Dherik

Reputation: 19050

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

Upvotes: 0

user655261
user655261

Reputation: 99

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.

Upvotes: 0

dahlbyk
dahlbyk

Reputation: 77520

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.

Upvotes: 1

Related Questions