Linq - Left outer join with dot notation?

Up vote 5 down vote favorite 1 share g+ share fb share tw.

Here's the query expression: var query = from you in db. Users join d in db. Defects on u.

UserID equals d. UserID into defectsGroup from d in defectsGroup.DefaultIfEmpty() select new { u, d }; Here's what I tried: var query2 = db.Users. GroupJoin(db.Defects.DefaultIfEmpty(), you => u.

UserID, d => d. UserID, (user, defect) => new { user, defect }); But defect is showing as IEnumerable rather than just Defect. I also tried: var query2 = db.Users.

GroupJoin(db. Defects, you => u. UserID, d => d.

UserID, (user, defect) => new { user, defect.DefaultIfEmpty() }); Which simply doesn't compile. All the online examples seem to use the (clearer) query syntax. C# linq linq-to-entities link|improve this question edited Mar 30 '11 at 16:09 asked Mar 30 '11 at 14:43Adam Rackis25.1k42055 95% accept rate.

I think you want this: var query2 = db.Users. GroupJoin(db. Defects, you => u.

UserId, d => d. UserID, (u, defectsGroup) => new { u, defectsGroup}) . SelectMany(z => z.defectsGroup.DefaultIfEmpty(), (z, d) => new { z.

U, d }); See my Edulinq blog post on query expressions for more details.

2 Wow - I guess that's why all the samples use query syntax for that :) – Adam Rackis Mar 30 '11 at 14:54 @Adam: Yeah, joins are rather simpler in query syntax :) – Jon Skeet Mar 30 '11 at 15:32 all the documentation I can find at Microsoft on DefaultIfEmpty says (and the examples show) that it returns an enumeration of one default item when the given enumeration is empty. Left outer join examples all show that it returns a default item when the PARTICULAR item in an enumeration is null. I see that this works, but where is the doc for this particular (apparently different) method?

THANKS! – Kelly Cline Apr 26 '11 at 14:48 1 @Kelly: I'm not sure what you mean. The point is that GroupJoin will end up with an empty group "on the right" when there are no matches for the "left" element.

SelectMany is then pairing each "left" entry with a "right" entry - but using a "right" entry of null if the group is empty. – Jon Skeet Apr 26 '11 at 14:53.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions