title: LINQ Grouping dynamically
body: <p>I have a class list of records, so user can select to group rows dynamically by property name. For example <code>MenuText</code>, <code>RoleName</code> or <code>ActionName</code>. Then  I have to execute grouping so I need a generic method to handle grouping by passing column name. </p>
  
  <p>Example :</p>
  
  <pre><code>public class Menu
  {
    public string MenuText {get;set;}
    public string RoleName {get;set;}
    public string ActionName {get;set;}
  }
  
  public class Menus 
  {
   var list = new List&lt;Menu&gt;();
   list.Add( new Menu {MenuText="abc",RoleName ="Admin", ActionName="xyz"};
   list.Add( new Menu {MenuText="abc",RoleName ="Admin", ActionName="xyz"};
   list.Add( new Menu {MenuText="abc1",RoleName ="Admin1", ActionName="xyz1"};
   list.Add( new Menu {MenuText="abc1",RoleName ="Admin1", ActionName="xyz1"};
  
    /// columnName :- Name of the Menu class ( MenuText  or RoleName  or ActionName)
  
    public IEnumerable&lt;IGrouping&lt;string,IEnumerable&lt;Menu&gt;&gt;&gt; GroupMenu(string columnName)
    {
            // Here I want to get group the list of menu by the columnName 
    }
  }
  </code></pre>