在.NET 4和多核環境中,如果我們使用DataLoadOptions.LoadWith,linq to sql datacontext對象是否會利用新的並行?LinqToSql - 並行 - DataContext和並行
編輯
我知道LINQ to SQL的不普通的並行查詢。我想知道的是,當我們指定DataLoadOption.LoadWith時,它是否使用並行化來執行每個實體與其子實體之間的匹配?
實施例:
using(MyDataContext context = new MyDataContext())
{
DataLaodOptions options =new DataLoadOptions();
options.LoadWith<Product>(p=>p.Category);
return this.DataContext.Products.Where(p=>p.SomeCondition);
}
生成以下SQL:
Select Id,Name from Categories
Select Id,Name, CategoryId from Products where p.SomeCondition
時創建的所有產品
,我們將有一個
categories.ToArray();
Parallel.Foreach(products, p =>
{
p.Category == categories.FirstOrDefault(c => c.Id == p.CategoryId);
});
或
categories.ToArray();
foreach(Product product in products)
{
product.Category = categories.FirstOrDefault(c => c.Id == product.CategoryId);
}
?
不要忘記標記您最喜歡的答案;-) – Steven 2010-06-22 11:33:37
@Steven:我希望能回答我的編輯... – Gregoire 2010-06-22 13:43:51
L2S內部沒有任何並行優化。查看我的更新。 – Steven 2010-06-22 14:29:40