Showing posts with label lambda. Show all posts
Showing posts with label lambda. Show all posts

May 3, 2013

Linq lambda group by aggregate by multiple columns



Example of grouping input DataTable by string column and getting aggregate MAX for second bool column:
     var sTables = (bindSrcColumns.DataSource as DataTable).Rows.Cast<DataRow>())
                        .GroupBy(r =>   ColumnsHelper.GetTablePart(r[EDITORCOLUMN_FIELDNAME].ToString()))
                        .Select(g => new Tuple<string, bool>(g.Key, g.Max(m => m[EDITORCOLUMN_ISSELECTED] as bool? ?? false)))
                        .OrderBy(s=>s.Item1)
                        .ToList();