Hello, I have the following 2 classes:
public class EstoqueItem {
[Key]
public int Id { get; set; }
public decimal Qtd { get; set; }
public Estoque Estoque { get; set;}
}
public class Estoque {
[Key]
public int Id { get; set; }
public ICollection<EstoqueItem> Itens { get; set; }
}
At some point, I return a List<Estoque>
and need to group all ICollection<EstoqueItem>
by Id and add their quantities. It would look something like the SQL below:
SELECT Id, SUM(Qtd) as Qtd,
FROM EstoqueItem
WHERE /* as condições que retornam a lista aqui */
GROUP BY Id
How do I concatenate the sublists of the stock, grouping by id and summing their quantities in the end?