I have a complex entity CostPageDTOas shown below:
public class CostPageDTO
{
public string CostPageNumber { get; set; }
public string D
I'm assuming your database query returns a join between CostPage and Item. If that's the case, first you have to group your rows to get the values for CostPage, after that project to your DTO type. I really doubt that you'll see much benefit in parallelizing the code.
Your code should look roughly like this:
costPages = table.AsEnumerable().GroupBy(dr=> new
{
CostPageNumber = dr[0].ToString(),
Description = dr[1].ToString(),
OrderType = Convert.ToChar(dr[2].ToString()),
VendorName = dr[3].ToString()
})
.Select(x => new CostPageDTO(){
CostPageNumber = x.Key.CostPageNumber,
Description = x.Key.Description,
OrderType = x.Key.OrderType,
VendorName = x.Key.VendorName,
Items = x.Select(dr=> new ItemDTO{
//ItemDTO mapping goes here
ItemID=dr[Constants.SearchPage.ITMID].ToString()
}).ToList()
}).ToList();