Groupby in linq with multiple user-specifed columns at runtime


  • Hi,

    I want to group the query by multiple columns which are selected by user. I am trying to use anonymous member variables as shown below but this will restrict me to group by single column.

    var grouped = filteredTable.AsEnumerable().GroupBy(p => new { column1 = p.Field<string>("Field1") });

    What i need is let say i have employee table with structure,

    empid, deptid, empname, empworklocation, empemail

    I have a UI in which i ask user to group the table by their choice. For instance user selects to group the table by deptid and empworklocation.

    How could i group my result with columns provided at runtime. Any help will be appreciated.

    Tuesday, July 16, 2013 5:55 AM