Dynamic Group By in LINQ VB RRS feed

  • Question


    Is there a way in a LINQ query to specify at runtime which property of the object to Group on?


    For example I have this code:


    Dim Items = From c In _CampaignData _

    Group c By Name = c.AccountGroupName Into g = Group _

    Where Name = SearchName


    At the moment this is grouping by AccountGroupName but I might want to group it by other properties as well such as ClientName, ContactName, etc.  Rather than having a seperate query for each property is there a way to declare it somehow and pass it into the query at runtime?

    Friday, November 7, 2008 10:12 AM

All replies