/// <summary> /// Generate Distinct Data Table from the Data Table Generated from server. /// </summary> Func<CancellationTokenSource, DataGridCollectionView, DataTable, DataTable> GetDistinctTable = (cancellationToken, DqmDataGridCollectionView, ResultDataTable) => { var distinctCol = DqmDataGridCollectionView.SortDescriptions.ToList(); if (distinctCol.Any()) { var _distinctColumns = from n in distinctCol select new { col = n.PropertyName.Split('_')[1] }.col; var dtLinq20 = new DataTable(); foreach (var item in _distinctColumns) { var existingColumn = ResultDataTable.Columns[item]; var _dColumn = new DataColumn { ColumnName = existingColumn.ColumnName, DataType = existingColumn.DataType, DefaultValue = existingColumn.DefaultValue, AllowDBNull = existingColumn.AllowDBNull, Caption = existingColumn.Caption }; dtLinq20.Columns.Add(_dColumn); } DataTable DistinctDataTable = null; try { DistinctDataTable = ResultDataTable.AsEnumerable().AsParallel().WithCancellation(cancellationToken.Token) .Select(row => { var newRow = dtLinq20.NewRow(); foreach (var item in _distinctColumns) { newRow[item] = row[item]; } return newRow; }) .Distinct(DataRowComparer.Default).CopyToDataTable(); } catch (Exception) { return null; } DistinctDataTable.TableName = "Distinct_TBL"; return DistinctDataTable; } return null; };
Quote:Proactor Pattern
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)