TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Navin Subramanian
NA
7
1.1k
Applications slow down when getting distinct of 50K+ records
Oct 3 2016 1:05 AM
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
/// <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
;
};
But for me it's taking too much of my applications load time. can any one suggest me a best solution?
Reply
Answers (
7
)
Biometric system
heading wise value bind