I have two lists
var left={[ID=1,Name='A',Qty1=0,Qty2=5],[ID=2,Name=B,Qty1=0,Qty2=52]};
var right={[ID=1,Name='A',Qty1=57,Qty2=0],[ID=2,Name=B,Qty1=84,Qty2=0]};
var outer=left.union(right);
I want to get the following result:
outer={[ID=1,Name='A',Qty1=57,Qty2=5],[ID=2,Name=B,Qty1=84,Qty2=52]}
How do I get that? How to write the comparator class?
Edit: I have two lists
var target=(...new ClassA{ID=a.ID,Name=a.Name,TargetQty=b.TargetValue}).ToList();
var sales=(....new ClassA{ID=a.ID,Name=a.Name,SalesQty=b.SaleValue}).ToList();
Now I want a full outer join. How can I get that?
It sounds like you possibly want an inner join:
var query = left.Join(right, l => l.Id, r => r.Id,
(l, r) => new { l.Id, l.Name, r.Qty1, l.Qty2 });
(You may want to join on both Id
and Name
; it's not clear whether the Id
is enough.)
See more on this question at Stackoverflow