它是确定使用PLINQ为的ForAll大容量插入到数据库? [英] is it ok to use plinq ForAll for a bulk insert into database?
本文介绍了它是确定使用PLINQ为的ForAll大容量插入到数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在做这样的:
entities.AsParallel().ForAll(o => repository.Insert(o));
时,这个好,我该怎么有这更表现?
is this good, am I going to have more performance with this ?
推荐答案
没有。
此人能更快,因为它利用了paralellism到SQL,但最终的SQL有使该表(页)的锁,因为它使插入。 因此,每个paralell请求后,又再次执行。
This one can be faster, as it leverages the paralellism to the SQL, but in the end the SQL has to make a lock for the table (page), as it makes an insert. therefore each paralell request is executed after another again.
如果你想批量插入,不是做出一个SP接受所有条目(例如,使用具有SQL 2008表),或做它LINQ2SQL。
If you want to make a bulk insert, than make a SP accepting all entries (e.g. a table with SQL 2008.) or do it with Linq2SQL.
这将是正确的设计解决方案。
that would be the correct design solution.
这篇关于它是确定使用PLINQ为的ForAll大容量插入到数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文