2017-08-06 53 views
0

我需要填充包含两个集合的Product对象。 当前的代码工作正常,并填充Product.GraphicItems集合,但我也需要填充Product.InfoItems集合,但我无法弄清楚多个集合的语法。在同一类型上填充多个集合

当前选择

var result = await this.Context.ShopCategorys 
    .Include(cat => cat.InfoItems) 
    .Include(cat => cat.Products) 
     .ThenInclude(prd => prd.GraphicItems) 
      .ThenInclude(itm => itm.Graphic) 
       .ThenInclude(gfx => gfx.Items) 
    .SingleAsync(cat => cat.Id.Equals(id)); 

Product.cs

[Table("ShopProduct")] 
public class Product : BaseShop 
{ 
    public bool Active { get; set; } = true; 
    public int CategoryId { get; set; } 
    public int CultureId { get; set; } = -1; 
    public List<ProductInfo> InfoItems { get; set; } = new List<ProductInfo>(); 
    public List<ProductGraphic> GraphicItems { get; set; } = new List<ProductGraphic>(); 
} 

ProductInfo.cs

[Table("ShopProductInfo")] 
public class ProductInfo : BaseShop, IInfoItem 
{ 
    public int? ProductId { get; set; } 
    public int CultureId { get; set; } 
    public Culture Culture { get; set; } 
    public string Name { get; set; } 
    public string Description { get; set; } 
} 

回答

0

解决方案:

var result = await this.Context.ShopCategorys 
    .Include(cat => cat.InfoItems) 
    .Include(cat => cat.Products) 
     .ThenInclude(prd => prd.InfoItems) 
    .Include(cat => cat.Products) 
     .ThenInclude(prd => prd.GraphicItems) 
      .ThenInclude(itm => itm.Graphic) 
       .ThenInclude(gfx => gfx.Items) 
    .SingleAsync(cat => cat.Id.Equals(id)); 
相关问题