What are ExecuteUpdate and ExecuteDelete in EF Core?
Quick Answer
ExecuteUpdate and ExecuteDelete (EF Core 7+) run a single set-based UPDATE/DELETE statement directly against the database from a LINQ query — no loading entities, no change tracking, no per-row round trips. Use them for bulk operations like “mark all stale carts abandoned”.
Before EF Core 7, updating a thousand rows meant loading a thousand entities, changing each one, and saving — all in memory. ExecuteUpdate and ExecuteDelete let me express the operation as a LINQ Where and have EF translate it to a single set-based UPDATE or DELETE statement, with nothing loaded and nothing tracked. Great for maintenance jobs like expiring old sessions. The things to remember are that they execute right away rather than on SaveChanges, and they don't go through the change tracker, so if I've already loaded some of those entities, those copies are now out of date.
- Before EF 7, a bulk update meant loading every matching entity, changing it and calling
SaveChanges— N entities in memory, one big transaction. db.Carts.Where(c => c.UpdatedAt < cutoff).ExecuteUpdate(s => s.SetProperty(c => c.Status, Status.Abandoned))→ one SQL statement.ExecuteDelete()similarly issues oneDELETE ... WHERE ....- Caveats: they run immediately (not deferred to
SaveChanges), they bypass the change tracker so any tracked copies of those entities are now stale, and they don't fire EF interceptors,SaveChangesevents or client-side validation.