none
Group By RRS feed

  • Question

  • How do I do something  like this in LINQ:

    select Diversity, count(*), AVG(Rating), AVG(Age) from  HeadTable
    group by Diversity


    Thanks

    Jay

     
    Tuesday, February 24, 2009 11:27 PM

Answers

  • from h in db.Heads
    group h by h.Diversity into g
    select new {Diversity = g.Key, Count = g.Count(), Rating = g.Average(h => h.Age), Age = g.Average(h => h.Age)}


    Wayward LINQ Lacky
    • Marked as answer by EJLindsay Wednesday, February 25, 2009 4:48 AM
    Wednesday, February 25, 2009 4:00 AM
    Moderator

All replies

  • from h in db.Heads
    group h by h.Diversity into g
    select new {Diversity = g.Key, Count = g.Count(), Rating = g.Average(h => h.Age), Age = g.Average(h => h.Age)}


    Wayward LINQ Lacky
    • Marked as answer by EJLindsay Wednesday, February 25, 2009 4:48 AM
    Wednesday, February 25, 2009 4:00 AM
    Moderator
  • Matt - Thank you.  It works.

    How do I do the same thing using the extension method format:

    db.Heads.GroupBy(......

    Thanks
    Jay
    Wednesday, February 25, 2009 4:49 AM