在.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