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() }
精彩评论