daily pastebin goal
43%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. LINQ - Group DataTable by multiple columns determined at runtime
  2. // column source
  3. IEnumerable<string> columns;
  4. DataTable table;
  5.  
  6. IEnumerable<IGrouping<object, DataRow>> groupings = table
  7.     .AsEnumerable()
  8.     .GroupBy(row => ???);
  9.    
  10. Func<DataRow, IEnumerable<string>, string> f = (row, cols) =>
  11.     String.Join("|", cols.Select(col => row[col]));
  12.    
  13. IEnumerable<IGrouping<object, DataRow>> groupings = table
  14.     .AsEnumerable()
  15.     .GroupBy(row => f(row, columns));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top