1

我遇到过这个教程

http://mattberseth.com/blog/2008/01/building_a_grouping_grid_with.html

但是我正在努力用 C Sharp 编写 LinqDataSource 查询。

var o = (from c in x group c by c.Date into cc select new { Group = cc.Key, ItemCount = cc.Count() });

以上很好,但是如何根据我发布的链接中的 LinqDataSource 将“It as Items”添加到上述查询中。

4

2 回答 2

0

我在您的查询中添加了代码

  var o = 
    (from c in x 
     group c by c.Date into cc 
     select new { Group = cc.Key, ItemCount = cc.Count() });

    foreach (var grp in o)
    {
        Console.WriteLine("\nCategoryID Key = {0}:", grp.Key);
        foreach (var item in grp)
        {
            Console.WriteLine("\t{0}", item.Items);//Replace with your property
        }
    }

您可以使用 yield 来枚举

于 2012-08-27T20:08:42.013 回答
0

group子句创建IGroupings。AnIGrouping基本上是IEnumerable带有键的 an,因此访问它的项目就像访问 anIEnumerable的项目一样。此语句使用ToList(),但您也可以使用AsEnumerable()or ToArray()

var o = from c in x 
        group c by c.Date into cc 
        select new { Group = cc.Key, Items = cc.ToList(), ItemCount = cc.Count() };
于 2012-08-28T01:08:37.350 回答