I am having Application slowness when i suppose to get distinct out a DataTable which has 50k+ records. i am using the below code to do it
-
-
-
- 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;
- };
But for me it's taking too much of my applications load time. can any one suggest me a best solution?