How to make LEFT JOIN in Lambda LINQ expressions

c# entity-framework linq

Accepted Answer

And this is how it might be expressed more intricately using lambda expressions:

order.Items
   .GroupJoin (
      productNonCriticalityList, 
      i => i.ProductID, 
      p => p.ProductID, 
      (i, g) => 
         new  
         {
            i = i, 
            g = g
         }
   )
   .SelectMany (
      temp => temp.g.DefaultIfEmpty(), 
      (temp, p) => 
         new  
         {
            i = temp.i, 
            p = p
         }
   )
22
2/3/2014 9:12:36 PM

Popular Answer

I would advise converting tofrom syntax, as well as theinto keyword.

While performing the same function as the method syntax, it is far more understandable (IMO).

(from l1 in myFirstDataSet
join l2 in mySecondDataSet on l1.<join_val> equals l2.<join_val> into leftJ
from lj in leftJ.DefaultIfEmpty()
where <your_where_clause>
select <something>).ToList();


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow