LINQ等效于以下内容:
SELECT Mytable.A, MyTable.B, SUM(MyTable.C)
FROM MyTable
GROUP BY Mytable.A, MyTable.B
ORDER BY Mytable.A, MyTable.B
这在SQL中是微不足道的,但在LINQ中似乎非常困难。我错过了什么?
答案 0 :(得分:5)
我现在无法访问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() }