C# 4.0 将项目添加到集合中的集合
这是我的对象结构C# 4.0 将项目添加到集合中的集合,c#-4.0,C# 4.0,这是我的对象结构 Group has List of Offers Offer has GroupId List of Products 如何根据组ID将产品添加到现有的产品列表中 此代码正在添加产品,但会覆盖现有产品 Group.OffersList.Where(x => x.GroupId == "1") .SelectMany(x => x.ProductList)
Group has
List of Offers
Offer has
GroupId
List of Products
如何根据组ID将产品添加到现有的产品列表中
此代码正在添加产品,但会覆盖现有产品
Group.OffersList.Where(x => x.GroupId == "1")
.SelectMany(x => x.ProductList)
.ToList().Add(Product);
Group.OffersList.Where(x => x.GroupId == "1")
.ToList()
.ForEach(x => x.Add(Product));