I have a Products table:
int id
string descricao
int quant
I want to do the following:
select descricao, sum(quant) from produtos group by descricao
How to do the above query in lambda
?
I have a Products table:
int id
string descricao
int quant
I want to do the following:
select descricao, sum(quant) from produtos group by descricao
How to do the above query in lambda
?
There are two ways to do it:
Direct on linq
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) });