This is my code:
DatabaseDataContext context = new DatabaseDataContext();
var sourceList = (from q in context.Table1 where col1< 2000 select q).ToList();
foreach( Type x in sourceList)
{
var task = Task.Factory.StartNew(() => FetchData(x));
}
FetchData(x)
{
SomeBO obj = new SomeBO();
obj.Prop1 = x.Table2.col;
obj.Prop2 = x.Table3.col;
}
When I execute this code, I get an exception 'There is already an open DataReader associated with this Command which must be closed first'. How could I make the method 'FetchData' to execute in parallel for all the list item in 'sourceList'?