Write a stored procedure to do the delete and call the stored procedure from Entity Framework.
C# , Entity Framework bulk delete Huge performance Issue
Indudhar Gowda
426
Reputation points
C# , Entity Framework bulk delete Huge performance Issue.
var db = new MyDbContext();
var itemsToDelete = db.MyTable.Where(x=>!x.active);
db.MyTable.RemoveRange(itemsToDelete);
db.SaveChanges();
I have 700000 rows to be deleted. Kindly let me know how do I solve this Problem...
More time taken in
db.MyTable.RemoveRange(itemsToDelete);
db.SaveChanges();
In the above 2 line its taking more time....Kindly let me know the best and Fastest way to Bulk Delete.
2 answers
Sort by: Most helpful
-
-
Karen Payne MVP 35,191 Reputation points
2022-04-20T15:41:00.72+00:00 If the constraint is it must be done with EF consider Bulk Delete library (free edition). Otherwise see the following.