views:

44

answers:

1

I dont seem to be able to find any evidence of multiple groupby being supported in LinqToSQl on the internet (I should probably buy a book :))

I'd like to be able to do this:

      var qry = from s in DBContext.Styles
               join artist in DBContext.Artists on s.ID equals artist.StyleID
               join track in DBContext.Tracks on s.ID equals track.StyleID
               group artist by new { s.ID, s.Name } into a
               group track by new { s.ID, s.Name } into t
               select new DTO.StyleSummary
               {
                   ID = a.Key.ID,
                   Name = a.Key.Name,
                   NumberOfArtists = a.Count(),
                   NumberOfTracks = t.Count()
               };

However the 2nd group statement prevents compilation.. Since this is possible in native sql how can I do this??

Thoughts? Is this even possible?

+1  A: 

Its because you don't really even need a groupby in this LINQ statement. You can just do

var qry = from s in DBContext.Styles
          join artist in DBContext.Artists on s.ID equals artist.StyleID into a
          join track in DBContext.Tracks on s.ID equals track.StyleID into t
          select new DTO.StyleSummary
          {
               ID = s.ID,
               Name = s.Name,
               NumberOfArtists = a.Count(),
               NumberOfTracks = t.Count()
          };

Note the into

Jeff Mc