I am new to LINQ and I may have painted myself on the corner. I have two lists (left and right), and I need:
a) Get relevant items based on specific fields
b) Get items on the left without matching on the right
c) Get items on the right that do not match on the left
A match is found if certain fields are equal. Other fields may or may not contain values, but should not affect match comparisons.
To get the element a, I did a JOIN on both lists:
var q = from a in r1 from b in r2 where a.Prop1 == b.Prop1 && a.Prop3 == b.Prop3 select new { a.Prop1, a.Prop2, b.Prop3 };
I'm not sure where to go from here. I think I can not use .Except() , because the other properties for both lists will be different and may lead to a breakdown of the comparison.
I also tried using Left Join and getting elements without matches:
var q = from c in r1 join p in r2 on c.Prop1 equals p.Prop1 into cp from p in cp.DefaultIfEmpty() select new { Prop1 = c.Prop1, Prop2 = p == null ? "N/A" : p.Prop2 };
however, I found that you cannot compare more than one field for comparison.
Do you have multiple fields on Left Join with LINQ? Are there other ways (other than LINQ) to get the difference between the two lists?
source share