Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 将项目添加到集合中的集合_C# 4.0 - Fatal编程技术网

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));