如何在LINQ TO SQL中按多列分组?

时间:2022-09-06 22:57:30

How do you group by multiple columns in LINQ TO SQL?

如何在LINQ TO SQL中按多列分组?

db.Table.GroupBy(a => a.column1.ToString() + a.column2.ToString())

It seems ugly and with poor performance, and I don't even know if it works. Which is the right way to do it?

它看起来很丑陋,表现不佳,我甚至不知道它是否有效。这是正确的方法吗?

1 个解决方案

#1


16  

try grouping by an anonymous type:

尝试按匿名类型分组:

group by new { item.Col1, item.Col2 }

you'll then be able to access Key.Col1, etc

然后你就可以访问Key.Col1等了

#1


16  

try grouping by an anonymous type:

尝试按匿名类型分组:

group by new { item.Col1, item.Col2 }

you'll then be able to access Key.Col1, etc

然后你就可以访问Key.Col1等了