none
Adding a Where and OrderBy clause to a Group Count Query

    Question

  • I have this query ..

    Dim g = From s In ml.Songs _
            Group s By Key = s.Artist Into artists = Group
            Select New With {.Artist = Key, .Count = artists.Count()}

    I'd like to add something like "Where Genre = 'Pop'" (I imagine this would be done before the grouping ?)

    and then order the grouped results by Artist.

    Baffled !

    Thursday, May 15, 2014 8:44 AM

Answers

  • Dim v = From s In songs
    Where s.Genere = "G1"
    Order By s.Artist
    Group s By Key = s.Artist Into artists = Group
    Select New With {.Artist = Key, .Count = artists.Count()}


    TejasJ.

    Thursday, May 15, 2014 1:21 PM
  • Hi theresonlyonefinmaf;

    Try this version to see if it gives you what you are looking for.

    Dim g = From s In ml.Songs _
            Where s.Genre = "Pop" _
            Group s By Key = s.Artist Into artists = Group _
            Order By Key _
            Select New With {.Artist = Key, .Count = artists.Count()}


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, May 16, 2014 3:09 PM

All replies

  • Dim v = From s In songs
    Where s.Genere = "G1"
    Order By s.Artist
    Group s By Key = s.Artist Into artists = Group
    Select New With {.Artist = Key, .Count = artists.Count()}


    TejasJ.

    Thursday, May 15, 2014 1:21 PM
  • Hi theresonlyonefinmaf;

    Try this version to see if it gives you what you are looking for.

    Dim g = From s In ml.Songs _
            Where s.Genre = "Pop" _
            Group s By Key = s.Artist Into artists = Group _
            Order By Key _
            Select New With {.Artist = Key, .Count = artists.Count()}


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, May 16, 2014 3:09 PM