开发者

Simple Linq grouping

how to use group by in Linq.

SqlServer Sample

select 
    ActionGroupName,  
    sum(cast(isnull(solicit_count,0) as int)) as 'SolicitCount' 
from 
    [solicits]
group by
    ActionGroupName

my linq version

var groupbyfilter = from v in lstSale
                    group v by v.ActionGroupName into g
                    select g.ActionGroupName, sum(g.solicit_count)

i am not gettin开发者_StackOverflow社区g it in proper way.


Try:

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)
                    };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜