In .NET 4 and a multi-core environment, the linq to sql datacontext object uses new parallels if we use DataLoadOptions.LoadWith?
EDIT
I know that linq to sql does not parallelize regular queries. I want to know when we specify DataLoadOption.LoadWith, does it use concurrency to match each object and its entities?
Example:
using(MyDataContext context = new MyDataContext()) { DataLaodOptions options =new DataLoadOptions(); options.LoadWith<Product>(p=>p.Category); return this.DataContext.Products.Where(p=>p.SomeCondition); }
generates the following sql:
Select Id,Name from Categories Select Id,Name, CategoryId from Products where p.SomeCondition
when all products are created, we will have
categories.ToArray(); Parallel.Foreach(products, p => { p.Category == categories.FirstOrDefault(c => c.Id == p.CategoryId); });
or
categories.ToArray(); foreach(Product product in products) { product.Category = categories.FirstOrDefault(c => c.Id == product.CategoryId); }
?
Gregoire
source share