开发者

Adding an item to a Collection within a Collection

开发者 https://www.devze.com 2023-03-07 19:01 出处:网络
This is my object structure, Group has List of Offers Offer has GroupId List of Products How can I add a product to the already existing List of products based on Group ID

This is my object structure,

Group has         
     List of Offers
Offer has 
     GroupId
     List of Products

How can I add a product to the already existing List of products based on Group ID

This code is adding the Product but overwriting the existing product

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

精彩评论

暂无评论...
验证码 换一张
取 消