RasmusKL RasmusKL - 5 months ago 36
SQL Question

Multiple deletions using LINQ (more specifically Linq2Nhibernate, but...)

Is there any smart way to do this?

If using

, you really seem to have to rely on
or the likes to do multiple deletes from a database (without loading up and deleting one by one)?

It doesn't seem like
have it either? I just want something that can do stuff like:

DELETE FROM Accounts WHERE amount < 1000

Any ideas?


The short answer is: you can't.

You can do something like:

var q = from account in dataContext.Accounts
    where account.amount < 1000
    select account;


But, because the framework needs to track concurrency issues it will always execute separate deletes (so if you have 500 rows that would be deleted, it will send 500 delete statements)

For a longer version and a solution see: http://www.aneyfamily.com/terryandann/post/2008/04/Batch-Updates-and-Deletes-with-LINQ-to-SQL.aspx