title: IEnumerable Group By user specified dynamic list of keys
body: <p>I have a class like</p>
  
  <pre><code>public class Empolyee
  {
      public string Designation {get ;set;}
      public string Discipline {get ;set;}
      public int Scale {get ;set;}
      public DateTime DOB {get ;set;}
      public int Sales {get ;set;}
  }
  </code></pre>
  
  <p>and have records of all employees in an enumerable say </p>
  
  <pre><code>List&lt;Employee&gt; Employees;
  </code></pre>
  
  <p>and a list of string keys like </p>
  
  <pre><code>var Keys = new List&lt;string&gt;()
  {
      "Designation",
      "Scale",
      "DOB"
  };
  </code></pre>
  
  <p>assume that elements of list "Keys" are user specified and user may specify no or many key elements.</p>
  
  <p>now i want to Group all "Employees" with the keys specified in list "Keys" and select only the properties specified in "Keys" plus Sum of Sales for each group.</p>
  
  <p>out of 3 solutions i tried to use, following looked applicable but could not use it because don't know how list "Keys" will be converted to anonymous type </p>
  
  <pre><code>Employees.GroupBy(e =&gt; new { e.Key1, e.Key2, ... })
      .Select(group =&gt; new {
          Key1 = group.Key.Key1,
          Key2 = group.Key.Key2,
          ...
          TotalSales = group.Select(employee =&gt; employee.Sales).Sum()
      });
  </code></pre>