lambda中的tsql - 选择count group by

时间:2014-03-10 22:06:38

标签: c# lambda entity

如何在Lambda和LINQ中执行此查询?

select COUNT(*) as total, int_page
        from dbo.tbl_usuarios_online
           group by int_page
               order by total desc

我不想使用:

var lambda = ctx.tbl_usuarios_online.**SqlQuery**()

1 个答案:

答案 0 :(得分:1)

试试这个:

var result = ctx.tbl_usuarios_online.GroupBy(x => x.int_page)
                                    .Select(group => new { total = group.count(), 
                                                           int_page = group.Key })
                                    .OrderByDescending(y => y.total);