简体   繁体   English

二级分组,使用LINQ排序

[英]Two level group by, order by using LINQ

What is the LINQ equivalent of the following: 什么是LINQ等同于以下内容:

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

This is trivial in SQL, but seems to be very difficult in LINQ. 在SQL中这是微不足道的,但是在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: 我现在没有访问Visual Studio进行测试的权限,但它看起来应该像这样:

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() }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM