Search code examples
linqselectgroup-byigrouping

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


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 queryGroupDuplicates = from dlc in listDLC
                                   from song in dlc.songs
                                   group dlc by song.shortname into duplicates
                                   where duplicates.Count() > 1
                                   select duplicates;
        queryGroupDuplicates.Dump();

Solution

  • 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.