如何在Linq中使用group by
。
SqlServer示例
select
ActionGroupName,
sum(cast(isnull(solicit_count,0) as int)) as 'SolicitCount'
from
[solicits]
group by
ActionGroupName
我的linq版
var groupbyfilter = from v in lstSale
group v by v.ActionGroupName into g
select g.ActionGroupName, sum(g.solicit_count)
我没有以适当的方式得到它。
答案 0 :(得分:5)
尝试:
var groupbyfilter = from v in lstSale
group v by v.ActionGroupName into g
select new
{
ActionGroupName = g.Key,
Sum = g.Sum(x => x.solicit_count)
};