0
I have it
var grupo = from item in aliquotaProduto
group item by item.CFOP_ID into agrupamento
select new
{
Categoria = agrupamento.Key,
Quantidade = agrupamento.Count()
};
I can bring an ID_PROD in select in addition to Category and Quantity?
EDIT1
I did so
var grupo = from item in aliquotaProduto
group item by item.CFOP_ID into agrupamento
select new
{
Produto = agrupamento.Select(it => it.ID_PROD),
Categoria = agrupamento.Key,
Quantidade = agrupamento.Count()
};
but I’m having trouble working with it. I have the right Products, but I can’t do anything with them. How do I do that? How I now assign my share?
EDIT2
if I do so
var grupo = from item in objectProd
group item by new { item.CFOP_ID, item.ID_Prod };
I have it
Key = {{CFOP_ID = 5402, ID_PRO = 1 }}
Key = {{CFOP_ID = 5404, ID_PRO = 2 }}
Key = {{CFOP_ID = 5404, ID_PRO = 3 }}
if I do that:
foreach(var item in Lista)
{
item.vlrUnit = rateio * varCount;
//a varCount deveria vir 1 para CFOP = 5402 e 2 para CFOP = 5404. É isso que eu não sei fazer.
}
that’s exactly what I need to do.
I doubt it’ll work, but you tried to add a
.ToList()
in the end?agrupamento.Select(it => it.ID_PROD).ToList()
– Leandro Angelo
The problem, @Leandroangelo, is exactly working and I don’t know how to do and I have to, you know,.
– pnet
@Leandroangelo, so inside the product I have two items. A Prod with 5402 and quantity = 1 and the other with two Prod with 5404 and quantity = 2. I can’t get to item [1] with the two Prods. It’s hard to explain.
– pnet
you asked that same question some other way before, see my answer? I didn’t want to go down that line?
– Leandro Angelo
@Leandroangelo, maybe I could not explain my doubt. The following: I have 3 items. These items I group by cfop. Soon this grouping gave two records. One item with 5402 and two with 5404. I need to take my share and multiply by these Counts(1 and 2) so that in thin I have: The record 1 multiplied by 1 and the other two records multiplied by 2. It turns out that my foreach has 3 items and if I do a foreach inside the other foreach with the items grouped, it will only cycle twice and the third item will not be multiplied.
– pnet
You’ll still face the same problem... Foreach the grouping and multiply by the Product Count https://answall.com/questions/288656/agrupar-itens-dentro-de-um-foreach/288770#288770
– Leandro Angelo