2011-05-24 4 views
0

Ceci est ma structure d'objet,Ajout d'un élément à une collection dans une collection

Group has   
    List of Offers 
Offer has 
    GroupId 
    List of Products 

Comment puis-je ajouter un produit à la déjà existante Liste des produits à base d'ID Group

Ce code ajoute le produit mais en écrasant le produit existant

Group.OffersList.Where(x => x.GroupId == "1") 
       .SelectMany(x => x.ProductList) 
       .ToList().Add(Product); 

Répondre

0
Group.OffersList.Where(x => x.GroupId == "1") 
       .ToList() 
       .ForEach(x => x.Add(Product)); 
Questions connexes