0
I have a product table:
int id
string descricao
int quant
Here’s what I wanna do:
select descricao, sum(quant) from produtos group by descricao
How to make the above query in lambda
?
0
I have a product table:
int id
string descricao
int quant
Here’s what I wanna do:
select descricao, sum(quant) from produtos group by descricao
How to make the above query in lambda
?
5
There are two ways to do it:
Straight into the Linum
var result=from p in produto group p by p.descricao into g select new {descricao=g.Key,count=g.Sum(x=>x.quant)}
or with Extended Methods
var result = produto.GroupBy(x => x.descricao).Select(new { descricao = g.Key, count = g.Sum(x => x.quant) });
Browser other questions tagged c# lambda-expressions
You are not signed in. Login or sign up in order to post.
only managed to catch the
descricao
and thequant
, if I have more fields, how do I catch them?– Italo Rodrigo
Just add the other fields separated by comma
– Tiago S
I could not :/ I will create another question showing how I am doing to see if you help me.
– Italo Rodrigo