Deleting a large number of records takes a VERY long time Deleting a large number of records takes a VERY long time database database

Deleting a large number of records takes a VERY long time


Entity framework is not very good at handling bulk operations like this. You should use ExecuteStoreCommand to execute SQL directly against the data source in situations like this.

var deleteOld = "DELETE FROM CpuMeasurements WHERE curr.Timestamp < {0}";msdc.ExecuteStoreCommand(deleteOld, oldestAllowedTime);

By doing so you don't need to load the entities into memory (just to delete them) and issue thousands of delete commands to the database.


You should look at EntityFramework.Extended it was created to help with both bulk deletions and updates.

Using it, you could simply do:

msdc.CpuMeasurements.Delete(curr => curr.Timestamp < oldestAllowedTime);


The reason for this is that you execute a DB update for every single record. You need to do a bulk update.

EntityFramework.extended can handle this scenario.