title: LINQ group by query using reflected property name
body: <p>I want to populate a drop down with the public properties of a particular object, which I have done fine. But now when the user selects the value from the dropdown, I want it to group the DB table results by that column. I have tried using LINQ but I can only figure out how to explicitly group by an instance variables property, not by a reflection property. This is my method - the parameter passed in is the string name of the property. Eg it will be "Country" if the user wants to group by Customer.Country, it will be "State" if the user wants to group by Customer.State. But at the moment I have hard coded to group by "State" as I cannot figure out how to use the string value passed in with my LINQ query</p>
  
  <pre><code>private void DisplayReportAction(string category)
  {
      if (!string.IsNullOrEmpty(category))
      {
          SelectedCategory = category;
          _summaries.Clear();
  
          foreach (var custGroup in _customerInterface.CustomerInterface.GetAllCustomers().GroupBy(c =&gt; c.State)
              .Select(group =&gt; new
                                   {
                                       Category = group.Key,
                                       Count = group.Count()
                                   })
                                   .OrderBy(x =&gt; x.Category))
          {
              _summaries.Add(new CustomerReportSummaryViewModel(custGroup.Category, custGroup.Count));
          }
  
          ReportVisibility = Visibility.Visible;
      }
  }
  </code></pre>