开发者

Two level group by, order by using LINQ

What is the LINQ equivalent of the following:

SELECT Mytable.A, MyTable.B, SUM(MyTable.C)
FROM MyTable
GROUP BY Mytable.A, MyTable.B
ORDER BY Mytable.A, MyTable.B

This is trivi开发者_开发知识库al in SQL, but seems to be very difficult in LINQ. What am I missing?


I don't have access to Visual Studio right now to test it out but it should look like this:

from record in table
group record by new { record.A, record.B } into recGroup
orderby recGroup.Key.A, recGroup.Key.B
select new { recGroup.Key.A, recGroup.Key.B, C = recGroup.Select(p => p.C).Sum() }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜