Geni Lou

Geni Lou

  • NA
  • 101
  • 24.3k

LINQ Query convert to DTO

Feb 24 2021 12:31 PM
how can I convert the LINQ query below and convert into model?
 
var sales = _context.Sales
.Include(x => x.Product)
.GroupBy(x => new { x.ProductId, x.Name})
.Select(g => new{
Id = g.Key,
Name = g.Key.Name,
Quantity = g.Sum(s => s.Quantity)
});
var list = (List<ProductModel>)sales;
public class SupplyModel
{
public Guid Id { get; set; }
public string Name { get; set; }
public int Quantity { get; set; }
}

Answers (2)