I'm deleting about 5000 rows of my table on a clustered index, and EF takes almost 30 seconds to do it.
Logging the generated SQL shows it's doing one delete for every row:
DELETE [dbo].[Table]
WHERE ([ColumnID] = @0)
So there are 5000 transactions in total.
I've tried calling SaveChanges() in batches, but this doesn't appear to improve performance much, or change the above behaviour.
//loop
{
//get batch
db.Table.RemoveRange(batch);
db.SaveChanges();
}
I have looked at some other questions which point out this flaw of delete commands executed per row, but no suggestion is made afterwards: How do I delete multiple rows in Entity Framework (without foreach)
Is there any way of stopping EF executing one command per row? I'd like to avoid inline SQL if possible.