如何使用Dynamic LINQ迭代GroupBy组?

时间:2013-12-02 14:39:13

标签: linq dynamic-linq

如何遍历动态sql GroupBy创建的组(并读取其数据)

示例代码:

List<dtoMyAlbum> listAlbums = new List<dtoMyAlbum>();
for (int i = 0; i < 5000; i++)
{
    dtoMyAlbum album = new dtoMyAlbum
    {
        Author = "My Author",
        BookID = i,
        CurrSymbol = "USD",
        Price = 23.23,
        Shop = i % 3 == 0 ? "TESCO" : "HMV"
    };
    listAlbums.Add(album);
}

IQueryable<dtoMyAlbum> mydata = listAlbums.AsQueryable();

var mydataGrouped = mydata.GroupBy("Shop", "it");  

foreach (var group in mydataGrouped)
{
     var count = group.Count();   <-- HOW TO MAKE THIS WORK?
     var firstEntry = group[0]    <-- HOW TO MAKE THIS WORK? etc.
}

0 个答案:

没有答案