集团通过多列 - LINQ [英] Group By Multiple Columns - LINQ

查看:136
本文介绍了集团通过多列 - LINQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经列看到乘法群的例子,但对于类。我想一个EnumerableDataRowList做到这一点。但我得到无效的匿名类型成员声明

I have seen examples of multiply group by columns, but for classes. I am trying to do this for a EnumerableDataRowList. but I get "Invalid anonymous type member declarator."

                    EnumerableDataRowList<DataRow> enumerableRowCollection = new EnumerableDataRowList<DataRow>(reportData.Select("WeekKey <> '0'"));


                var groupedRows1 = from row in enumerableRowCollection
                                  group row by new {row["NETWORK"], row["Week"] };



另外,我看到有些人在合并案的一些列来获得相同的结果。

also, I seen some people combine the columns in some case to get the same results. Any benefit in doing it that way

推荐答案

您必须指定一个标识符中的值任何好处

You have to assign an identifier to the values:

         var groupedRows1 = from row in enumerableRowCollection
                            group row by new { Network = row["NETWORK"], Week = row["Week"] };

您通常不需要指定一个标识符,如果您使用的是字段或属性作为参考它只会重用成员的名字 - 但在这种情况下,您正在访问一个索引属性,所以没有办法摆脱它一个名字

You normally aren't required to specify an identifier if you're using a field or property reference as it'll just reuse the name of that member - but in this case you're accessing an indexer property, so there's no way to get a name from it.

这篇关于集团通过多列 - LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆