Skip to content

EF Core Batch Update — Complete Guide

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about EF Core Batch Update. We cover key concepts, practical examples, and best practices.

You need to update the Category of all products where Price > 100. Without batch operations, you load every product, modify each entity, and call SaveChanges — sending one UPDATE per product. EF Core batch update (EF Core 7+) generates a single SQL UPDATE.

Wrong

var products = await db.Products.Where(p => p.Price > 100).ToListAsync();
foreach (var p in products)
{
    p.Category = "Premium";
}
await db.SaveChangesAsync();

Output: SELECT * FROM Products WHERE Price > 100 followed by N individual UPDATE statements. Memory usage grows with the number of products.

Right (EF Core 7+)

await db.Products
    .Where(p => p.Price > 100)
    .ExecuteUpdateAsync(setters => setters
        .SetProperty(p => p.Category, "Premium")
        .SetProperty(p => p.LastModified, DateTime.UtcNow));

Output: Single SQL: UPDATE Products SET Category = 'Premium', LastModified = '2026-06-24' WHERE Price > 100. No data loaded into memory.

ExecuteUpdate supports any IQueryable, so you can compose complex filters:

await db.Orders
    .Where(o => o.Date < cutoff && o.Status == "Pending")
    .ExecuteUpdateAsync(s => s.SetProperty(o => o.Status, "Expired"));

Prevention

  • Use ExecuteUpdateAsync for bulk updates in EF Core 7+.
  • Use ExecuteDeleteAsync for bulk deletes.
  • Use ExecuteUpdate with multiple SetProperty calls for multi-column updates.
  • Compose Where clauses for targeted updates.
  • Use ExecuteUpdate in data maintenance and background jobs.
  • Fall back to ExecuteSqlRaw for complex updates EF Core cannot express.
  • Test that the generated SQL matches your expectations.

Common Mistakes with core batch update

  1. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  2. Using return to exit a function early instead of wrapping a pure value in the monad
  3. Mixing let bindings with <- bindings in do notation, producing type errors

These mistakes appear frequently in real-world EF code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

Does ExecuteUpdate work with all database providers?

SQL Server, PostgreSQL, SQLite, and Cosmos DB support ExecuteUpdate. Check your provider documentation. The generated SQL syntax varies by provider.

Can I use ExecuteUpdate with a join?

Yes, in EF Core 7+. You can use .Where() with navigation properties and EF Core translates the join. db.Products.Where(p => p.Category.Name == "Old").ExecuteUpdateAsync(...) generates an UPDATE with a JOIN.

Does ExecuteUpdate trigger interceptor events?

Yes. SaveChanges interceptors are NOT called — ExecuteUpdate bypasses the change tracker. However, DbCommandInterceptor intercepts the generated SQL command. Audit trails must handle this differently.

Batch operations power DodaTech's data maintenance and bulk processing pipelines. For more EF Core, visit DodaTech.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro