1
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 I need to group all the ICollection<EstoqueItem>
by Id and add up its quantities. It would be something like 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 adding their quantities at the end?
Its structure does not make much sense... Stock Room you have several items and each has its quantity?
– Leandro Angelo
I have several stocks and these stocks have several unique items. This is just a part of the structure itself (maybe that’s why it doesn’t make sense to you), it has this format because I’m creating a project for a logistics company
– LeandroLuk
I tried to make the structure of my problem as simple as possible to arrive at a viable solution...
– LeandroLuk
And this "cyclical" reference? An Item has a stock and a Stock has a collection of items
– Leandro Angelo