"labelProducts": [ { "labelProductId": 0, "productId": 0, "labelId": 1, "product": null, "label": null } ],
public async Task<IEnumerable<ProductDto>> GetProducts() { var product = await _db.Products .Select(p => new ProductDto { Name = p.Name, Description = p.Description, Colours = p.Colours.Select(c => new ColourDto { Id = c.Id, Name = c.Name, // we only load what we need to show the colour Img = c.Img, Quantity = c.Quantity }).ToList(), LabelProducts = p.LabelProducts.Select(l => new LabelProductDto { LabelId = l.LabelId, Label = l.Label // and only what we need for the label }).ToList(), Price = p.Price, }) .ToListAsync(); // we only load the requested product return _mapper.Map<List<ProductDto>>(productList); }