Guest User

Untitled

a guest
Sep 14th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  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));
Add Comment
Please, Sign In to add comment