πŸ”„οΈ EF Core Bulk Update with Entity Framework Extensions

When using EF Core to update data, the typical process involves several steps:

  1. Load entities from the database into memory This is usually done using methods like Find, FirstOrDefault, or Where on the DbSet class.

  2. Modify the entity’s properties Once the entities are loaded, you update their properties as needed.

  3. Call SaveChanges() After making your changes, you call SaveChanges on the DbContext to persist them to the database.

Here’s a basic example that updates multiple entities:

language-csharp
|
var importCustomers = new List<Customer>
{
    new Customer { ID = 1, Name = "ZZZ Projects", City = "New York" },
    new Customer { ID = 2, Name = "Jonathan Magnan", City = "Montreal" }
    // Add more customers as needed
};

var importCustomersDict = importCustomers.ToDictionary(x => x.ID);

using (var context = new MyDbContext())
{
    // 1. Load entities from the database into memory
    var customers = context.Customers
        .Where(x => importCustomersDict.ContainsKey(x.ID))
        .ToList();

    // 2. Modify the entity's properties
    foreach (var customer in customers)
    {
        var importCustomer = importCustomersDict[customer.ID];
        customer.Name = importCustomer.Name;
        customer.City = importCustomer.City;
    }

    // 3. Call SaveChanges
    context.SaveChanges();
}

This approach works fine for a small number of entities β€” but what if you need to update 10,000 customers?

That’s where the BulkUpdate method from the Entity Framework Extensions library shines. It’s faster, cleaner, and skips all the heavy lifting:

  • ❌ No need to load entities first
  • ❌ No need to manually update properties
  • βœ… Just update your entities directly

By using the BulkUpdate method from ZZZ Projects, you can skip steps 1 and 2 β€” and update your entities directly in the database:

language-csharp
|
// @nuget: Z.EntityFramework.Extensions.EFCore
using Z.EntityFramework.Extensions;

var importCustomers = new List<Customer>
{
    new Customer { ID = 1, Name = "ZZZ Projects", City = "New York" },
    new Customer { ID = 2, Name = "Jonathan Magnan", City = "Montreal" }
    // Add more customers as needed
};

using (var context = new MyDbContext())
{
    // Easy to use
    context.BulkUpdate(importCustomers, options =>
        options.ColumnInputExpression = x => new { x.Name, x.City });
}

using (var context = new MyDbContext())
{
    // Supports async
    await context.BulkUpdateAsync(importCustomers, options =>
        options.ColumnInputExpression = x => new { x.Name, x.City });
}

You’ve just turned an inefficient, multi-step update into a single line of code that any developer can understand:

language-csharp
|
// @nuget: Z.EntityFramework.Extensions.EFCore
using Z.EntityFramework.Extensions;

context.BulkUpdate(importCustomers, options =>
    options.ColumnInputExpression = x => new { x.Name, x.City });

In this example, all imported customers will be updated, and only the Name and City properties will be affected.


πŸ“‰ Reduce Memory Usage When Saving Data

Processing millions of entities? EF Extensions can reduce memory usage while improving bulk operation performance.

Explore Performance Benefits →

πŸš€ Why Use the Bulk Update Method from Entity Framework Extensions?

The bulk update method from Entity Framework Extensions is the recommended solution for EF Core when you need to update large sets of data efficiently.

Entity Framework Extensions is the most popular and most complete library available, with over 50 million downloads and more than 5,000 paid customers. Bulk updating in EF Core with Entity Framework Extensions is up to 4x faster, reducing execution time by 75% (Online Benchmark).

It helps you optimize database performance by reducing the number of queries, making your code cleaner, and giving you full control over how updates are applied:

  • βœ… Update the way you want β€” Choose which properties to update, skip null values, apply conditions, and more.
  • βœ… Extremely fast β€” Update thousands or even millions of rows in seconds. See the Performance Comparison.
  • βœ… No need to load entities β€” Save time and memory by skipping entity tracking.
  • βœ… Flexible with hundreds of options β€” Fine-tune everything: batch size, conditions, behaviors, and more. Explore the Bulk Update Options.
  • βœ… Supports all major providers β€” SQL Server, MySQL, MariaDB, Oracle, PostgreSQL, SQLite.
  • βœ… Most advanced EF Core library β€” Supports inheritance, owned types, complex types, and more.

πŸ› οΈ Commonly Used Options with the the Bulk Update Method from Entity Framework Extensions

Here are some of the most frequently used options with the BulkUpdate method from the Entity Framework Extensions library:

  • ColumnPrimaryKeyExpression – Choose which properties to use as the primary key by providing a lambda expression. Only rows that match the key will be updated.
  • ColumnInputExpression – Select which properties should be updated by using a lambda expression. All other properties will be ignored.
  • IgnoreOnUpdateExpression – Specify which properties should be ignored during the update using a lambda expression. All other properties will be included.
  • UpdateMatchedAndConditionExpression – After matching rows by primary key, you can add extra conditions using a lambda expression. All specified property values must match between the entity and the database for the update to happen.
  • UpdateMatchedAndOneNotConditionExpression – Similar to the above, but only one of the specified property values needs to be different between the entity and the database for the row to be updated.
  • IncludeGraph – Set this to true if you want to update both the main entities and their related entities. For example, if you pass a list of Order that includes OrderItem, both will be updated. ⚠️ Be careful β€” if you want to apply specific options to a related entity type, you’ll need to configure them using IncludeGraphBuilder.
  • UseRowsAffected – Set this to true if you want to know how many rows were affected after the update. You can then access ResultInfo.RowsAffected or ResultInfo.RowsAffectedUpdated. πŸ‘‰ Learn more

πŸ“¦ How to Install Entity Framework Extensions

To use the bulk update method, install the Z.EntityFramework.Extensions.EFCore NuGet package:

language-powershell
|
PM> NuGet\Install-Package Z.EntityFramework.Extensions.EFCore
language-bash
|
> dotnet add package Z.EntityFramework.Extensions.EFCore

Entity Framework Extensions uses EF Core pinned versioning, so make sure the first digit of the package version matches your EF Core version. For example:

  • If you're using EF Core 10, use version v10.x.y.z
  • If you're using EF Core 9, use version v9.x.y.z
  • If you're using EF Core 8, use version v8.x.y.z
  • And so on...

Looking for a different version, like BulkUpdate for EF6? πŸ‘‰ Download it here


βœ… Final Thoughts

If you're still updating large numbers of rows using regular EF Core logic, it's time to make your life easier.

With just one line of code, the bulk update method from Entity Framework Extensions lets you:

  • Skip unnecessary steps
  • Dramatically boost performance
  • Customize everything to fit your needs

Whether you're dealing with 10 or 10 million rows, the bulk update method from Entity Framework Extensions gives you the speed, control, and simplicity you've been looking for.

Give it a try and see why over 5,000 companies already trust Entity Framework Extensions to handle their bulk operations. Once you use it, you won’t want to go back!


Looking for more resources? Here are some helpful links to learn more about the BulkUpdate method and Entity Framework Extensions, explore its documentation, and download the right version for your project.

πŸ“˜ Documentation

πŸ“¦ Downloads & Packages

πŸš€ Make EF Core Up to 15x Faster

Stop waiting for SaveChanges. Insert thousands of entities up to 15x faster and reduce saving time by 94% with Entity Framework Extensions.

Discover EF Extensions →

Date Modified: 2025-11-11
Author:

Edit this page in GitHub

Got any EF Core Question?