I have DataTable with 2 columns: Id(long), Date(DataTime). How to group this to get grouped list in linq:
2017.08.03
345675
877685
2017.08.04
988798
898967
675675
Next, I must to send each of group to stored procedure as a parameter. I can have about 300000 rows at data table so linq extension should be fast.
Ok. Now, I want to do something foreach groups. How Can I do it?
var GroupedbyDates = dataTable.AsEnumerable().GroupBy(x => ((DateTime)x["Date"]).Date);
for (var i = 0; i < threadCount; i++)
{
Task task = Task.Factory.StartNew(DoSomething);
tasks.Add(task);
}
private DoSomething()
{
while (true)
{
var item = ?? //one of groups;
if (item != null)
{
var result = DoSomething2();
HandleResult(result);
}
}
}
How to iterate on IGrouped??
UPDATE
I have something like this:
var r = dataTable.AsEnumerable()
.GroupBy(x => ((DateTime)x["Date"]).Year)
.ToDictionary(year => year.Key, g => g.GroupBy(x =>
((DateTime)x["Date"]).Month)
.ToDictionary(month => month.Key, d => d
.Select(t => new { Root_Id = t["Id"] })));
to:
2017.08.03
345675
877685
2017.08.04
988798
898967
675675