Interview frequency: …
Short answer
They execute UPDATE and DELETE directly in the database with one query, without loading and tracking records in memory or calling SaveChanges().
Explanation
Previously, deleting 1,000 inactive users required loading 1,000 objects into server memory, marking them for deletion in the Change Tracker, and calling SaveChanges(), which generated 1,000 SQL statements. ExecuteUpdateAsync and ExecuteDeleteAsync translate LINQ conditions directly into one SQL statement, such as DELETE FROM Users WHERE LastLogin < @date, completing in milliseconds with no server memory use.
Code example
// Immediate bulk delete with one query, without loading entities
await dbContext.Users
.Where(u => !u.IsActive && u.CreatedAt < cutoffDate)
.ExecuteDeleteAsync();Common mistakes
- Expecting ExecuteUpdate or ExecuteDelete to fire events or update the in-memory Change Tracker; they bypass it entirely.
Follow-up questions
- How does the EF Core Change Tracker work, and why should you use AsNoTracking() for read queries?
- What are Compiled Queries in EF Core, and when are they worth using?