c# - Deleting a large number of records takes a VERY long time -


i have database table (running on sql server 2012 express) contains ~ 60,000 rows.

i using following code purge old rows:

//deleting cpu measurements older (oldestallowedtime) var allcpumeasurementsquery = curr in msdc.cpumeasurements      curr.timestamp < oldestallowedtime select curr; foreach (var cpumeasurement in allcpumeasurementsquery) {   msdc.cpumeasurements.remove(cpumeasurement); } 

when number of deleted rows large (~90% or more of records in tables being deleted) operation takes exceptionally long. takes 30 minutes finish operation on relatively strong machine (intel i5 desktop).

  1. does seem normal behavior?

  2. any ideas can reduce operation's time?

thanks,

entity framework not @ handling bulk operations this. should use executestorecommand execute sql directly against data source in situations this.

var deleteold = "delete cpumeasurements curr.timestamp < {0}"; msdc.executestorecommand(deleteold, oldestallowedtime); 

by doing don't need load entities memory (just delete them) , issue thousands of delete commands database.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -