开发者

after group by in LINQ how to get to nested values using select

开发者 https://www.devze.com 2023-02-18 23:39 出处:网络
http://img51.imageshack.us/i/linqquestion.png/ Everything is in the picture. I just want to get to one of the highlighted values, for example size.

http://img51.imageshack.us/i/linqquestion.png/

Everything is in the picture.

I just want to get to one of the highlighted values, for example size.

code from picture :

        var queryGroupDuplic开发者_开发问答ates = from dlc in listDLC
                                   from song in dlc.songs
                                   group dlc by song.shortname into duplicates
                                   where duplicates.Count() > 1
                                   select duplicates;
        queryGroupDuplicates.Dump();


queryGroupDuplicates.First().First().size


So you just want to select those fields from any one of the items in the group? Well your picture shows the contents of what in the groups, so pick one of the items in the group and select the fields you want (let's pick the first one's values).

var queryGroupDuplicates =
    from dlc in listDLC
    from song in dlc.songs
    group dlc by song.shortname into duplicates
    where duplicates.Count() > 1
    let someItem = duplicates.First()
    select new
    {
        someItem.fileName,
        someItem.gameID,
        someItem.size,
        someItem.errorsDLC,
        someItem.packName,
    };


var queryGroupDuplicates = from dlc in listDLC
                           from song in dlc.songs
                           group dlc by song.shortname into duplicates
                           where duplicates.Count() > 1
                           select new
                           {
                           duplicatName = duplicates.Key,
                           DLCfiles = from DLCfile in duplicates
                                      select new {DLCfileName = DLCfile.fileName, packName = DLCfile.packName}
                           };

This code produces what's in the picture below: http://img846.imageshack.us/i/linqanswer.png/

MSDN - i got idea after seeing this, but thanks for your fast response anyway.

0

精彩评论

暂无评论...
验证码 换一张
取 消