score:0

Usually for joins and especially for left joins I use statement syntax.

Not tested, but would look something like this:

var result = from a in tableA
             from b in tableB.Where(x => x.col1 == a.col1 && x.col2 == a.col2 && a.col3 == 1).DefaultIfEmpty()
             select new { a.col1, a.col2, b.col3 };

By doing a .DefaultIfEmpty() on the join from tableB, it will treat this as a left join. If you leave out the .DefaultIfEmpty() then it will behave like an inner join.

score:0

You can find an extension that facilitates left joins with Dynamic Linq on GitHub: https://github.com/SikeyMael/LinqHelper


Related Articles