Search code examples
c#.netlinq.net-4.0plinq

is it ok to use plinq ForAll for a bulk insert into database?


I'm doing like this:

 entities.AsParallel().ForAll(o => repository.Insert(o));

is this good, am I going to have more performance with this ?


Solution

  • No.

    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.

    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.