如何在LINQ中对多个列进行分组
在SQL中与此类似:
SELECT * FROM <TableName> GROUP BY <Column1>,<Column2>
如何将其转换为LINQ:
QuantityBreakdown ( MaterialID int, ProductID int, Quantity float ) INSERT INTO @QuantityBreakdown (MaterialID, ProductID, Quantity) SELECT MaterialID, ProductID, SUM(Quantity) FROM @Transactions GROUP BY MaterialID, ProductID
使用匿名类型。
例如
group x by new { x.Column1, x.Column2 }