Linq to update a collection with values from another collection?

前端 未结 5 1206
北恋
北恋 2020-12-31 04:05

I have IQueryable baseList

and List someData

What I want to do is update attributes in some

5条回答
  •  盖世英雄少女心
    2020-12-31 04:24

    As mentioned before, it should be a combination of loop and LINQ

    foreach (var someDataItem in someData)
    {
        someDataItem.PropertyToUpdate = (baseList.FirstOrDefault(baseListItem => baseListItem .key == someDataItem.key) ?? new SomeClass(){OtherProperty = "OptionalDefaultValue"}).OtherProperty;
    }
    

提交回复
热议问题