first i compose the LINQ query this way which worked properly without any error. here is my code
(from bk in Brokers.AsParallel()
from prd in Periods.AsParallel()
from _dsDb in dsDb.Tables[0].AsEnumerable().AsParallel()
join _dtMain in dtMain.AsEnumerable().AsParallel()
on new
{
val1 = _dsDb.Field<int>("ParentID"),
val2 = _dsDb.Field<int>("ID"),
val3 = _dsDb.Field<string>("Section"),
val4 = _dsDb.Field<string>("LineItem"),
val5 = _dsDb.Field<string>("DisplayInCSM")
}
equals new
{
val1 = _dtMain.Field<int>("ParentID"),
val2 = _dtMain.Field<int>("ID"),
val3 = _dtMain.Field<string>("Section"),
val4 = _dtMain.Field<string>("LineItem"),
val5 = _dtMain.Field<string>("DisplayInCSM")
}
where _dsDb.Field<string>("RowType") == "LineItem"
&& _dsDb.Field<int>("ParentID") == ParentID
&& _dsDb.Field<int>("ID") == ID
&& _dsDb.Field<string>("Broker") == bk.BrokerCode &&
_dtMain.Field<string>("Type") == "Consensus"
&& _dtMain.Field<int>("ParentID") == ParentID
&& _dtMain.Field<int>("ID") == ID
&& _dtMain.Field<string>("Section") == Section
&& _dtMain.Field<string>("LineItem") == LineItem
&& _dtMain.Field<string>("DisplayInCSM") == DisplayInCSM
select new { _dsDb, _dtMain, bk, prd }).ToList()
.ForEach(x =>
{
x._dtMain.SetField("B_" + x.bk.BrokerCode + "_" + x.prd, (x._dsDb.Field<decimal?>(x.prd ?? "").ToString()));
x._dtMain.SetField("file_date", (x._dsDb.Field<string>("Revise Date")));
});
The moment i i use .AsParallel().ForAll() then program throwing error
Index was out of range. Must be non-negative and less than the size of the collection.
This way i use .AsParallel().ForAll() please review my code and tell me what is my mistake in code for which i am getting error.
how to fix the problem
(from bk in Brokers.AsParallel()
from prd in Periods.AsParallel()
from _dsDb in dsDb.Tables[0].AsEnumerable().AsParallel()
join _dtMain in dtMain.AsEnumerable().AsParallel()
on new
{
val1 = _dsDb.Field<int>("ParentID"),
val2 = _dsDb.Field<int>("ID"),
val3 = _dsDb.Field<string>("Section"),
val4 = _dsDb.Field<string>("LineItem"),
val5 = _dsDb.Field<string>("DisplayInCSM")
}
equals new
{
val1 = _dtMain.Field<int>("ParentID"),
val2 = _dtMain.Field<int>("ID"),
val3 = _dtMain.Field<string>("Section"),
val4 = _dtMain.Field<string>("LineItem"),
val5 = _dtMain.Field<string>("DisplayInCSM")
}
where _dsDb.Field<string>("RowType") == "LineItem"
&& _dsDb.Field<int>("ParentID") == ParentID
&& _dsDb.Field<int>("ID") == ID
&& _dsDb.Field<string>("Broker") == bk.BrokerCode &&
_dtMain.Field<string>("Type") == "Consensus"
&& _dtMain.Field<int>("ParentID") == ParentID
&& _dtMain.Field<int>("ID") == ID
&& _dtMain.Field<string>("Section") == Section
&& _dtMain.Field<string>("LineItem") == LineItem
&& _dtMain.Field<string>("DisplayInCSM") == DisplayInCSM
select new { _dsDb, _dtMain, bk, prd }).AsParallel()
.ForAll(x =>
{
x._dtMain.SetField("B_" + x.bk.BrokerCode + "_" + x.prd, (x._dsDb.Field<decimal?>(x.prd ?? "").ToString()));
x._dtMain.SetField("file_date", (x._dsDb.Field<string>("Revise Date")));
});
Getting error when i add AsParallel with ForAll
.AsParallel()
.ForAll(x =>
{
x._dtMain.SetField("B_" + x.bk.BrokerCode + "_" + x.prd, (x._dsDb.Field<decimal?>(x.prd ?? "").ToString()));
x._dtMain.SetField("file_date", (x._dsDb.Field<string>("Revise Date")));
});
Please help me to fix the problem. thanks