0

Microsoft has this help page for performing a left outer join, however it's in linq query syntax. What's the equivalent to this, using method syntax?

http://msdn.microsoft.com/en-us/library/bb397895.aspx

For example, I have two enumerables:

class TA {string Name{get;}}
class TB {string Name{get;}}
Enumerable<TA> A; 
Enumerable<TB> B;

The result I want is this:

var joined = 
  A.Select(a => new 
  { left = a, 
    right = B.FirstOrDefault(b => b.Name == a.Name) 
  });

This gives me what I need with just select and (effectively) a nested select. Perhaps this isn't an actual left outer join...

mackenir
  • 10,801
  • 16
  • 68
  • 100
  • See if http://msmvps.com/blogs/jon_skeet/archive/2011/01/28/reimplementing-linq-to-objects-part-41-how-query-expressions-work.aspx helps you. There's nothing specify about left outer joins in query syntax. – Jon Skeet Jun 13 '14 at 13:23
  • There's a answer on a similar question: http://stackoverflow.com/a/21584913/467172 – Anthony Jun 13 '14 at 13:32
  • possible duplicate of [LEFT OUTER JOIN in LINQ](http://stackoverflow.com/questions/3404975/left-outer-join-in-linq) – Anthony Jun 13 '14 at 13:33

1 Answers1

0

I've used something like

var q = (from a in db.Item1Set
         from b in db.Item2Set.Where(i2 => i2.Item1Id == a.Id).DefaultIfEmpty());
Janne Matikainen
  • 5,061
  • 15
  • 21