如何用linq编写group sql

时间:2015-03-31 11:01:04

标签: linq

我有一个如下的SQL:

select catalog,queryname,count(*) from table group by catalog,queryname

现在我如何在linq中编写并获取计数?

感谢

1 个答案:

答案 0 :(得分:1)

var g =
    from record in table
    group record by new
    {
        record.catalog, record.queryname
    } into mygroup
    select new 
    {
        catalog = key.catalog,
        queryname = key.queryname
        count = myGroup.Count()
    };