Linq to update a collection with values from another collection?
c#, collections, linq
Solution
To pair elements in the two lists you can use a LINQ join:
var pairs = from d in someData
join b in baseList.AsEnumerable()
on d.someCode equals b.myCode
select new { b, d };
This will give you an enumeration of each item in `someData` paired with its counterpart in `baseList`. From there, you can concatenate in a loop:
foreach(var pair in pairs)
pair.b.SomeData += pair.d.DataIWantToConcantenate;
If you really meant set concatenation rather than `+=`, take a look at LINQ's Union, Intersect or Except methods.
Problem
I have `IQueryable<someClass>` baseList and `List<someOtherClass>` someData What I want to do is update attributes in some items in baseList. For every item in someData, I want to find the corresponding item in baselist and update a property of the item. someOtherClass.someCode == baseList.myCode can I do some type of join with Linq and set baseList.someData += someOtherClass.DataIWantToConcantenate. I could probably do this by iteration, but is there a fancy Linq way I can do this in just a couple lines of code? Thanks for any tips, ~ck in San Diego