Bulk Updating Data With Dapper

Dapper provides the Execute method for updating data. However, a database roundtrip is required for every data you update. The more database roundtrips you do, the longer it will take to complete all your updates.

It is possible to dramatically reduce the number of database roundtrips by using the BulkUpdate method from the Dapper Plus third-party library.

Performance can be improved by up to 5000% and more depending on the provider (Online Benchmark).

📈 Handle Millions of Records Efficiently

Processing large datasets? Dapper Plus is built for high-performance bulk operations, helping your application scale without thousands of individual database commands.

Explore Bulk Performance →

Getting Started

NuGet Package: https://www.nuget.org/packages/Z.Dapper.Plus/

Documentation: Dapper Plus – Bulk Update

Dapper BulkUpdate

Dapper Plus BulkUpdate method allows you to update multiple entities in a single round trip. It is more efficient than updating each entity one by one and can help improve your application's performance by reducing the number of database calls.

  • The BulkUpdate method allows you to specify which properties to update.
  • With the BulkUpdate method, you can easily update thousands of records at once and make sure that your data is always up-to-date.

To perform a BulkUpdate, you need to pass your entities in the parameter:

language-csharp
|
// @nuget: Z.Dapper.Plus
using Z.Dapper.Plus;

// Easy to use
connection.BulkUpdate(products);

// Easy to customize
connection.UseBulkOptions(options => options.BatchSize = 1000)
		  .BulkUpdate(products);

Online Example

Dapper BulkUpdate with Global Context Mapping

An entity type can be mapped more than once using a mapping key. For example, for a specific scenario, you only want to update some properties:

language-csharp
|
// @nuget: Z.Dapper.Plus
using Z.Dapper.Plus;

// Global Mapping requires to be mapped globally only once
DapperPlusManager.Entity<Customer>("Customer_CustomMap")
	.Map(nameof(Customer.Email))
	.Map(nameof(Customer.Name));
 
// ...code...
 
connection.BulkUpdate("Customer_CustomMap", customers);

Dapper BulkUpdate with Instance Context Mapping

By using an instance context mapping, you can choose to map your entity type at runtime:

language-csharp
|
// @nuget: Z.Dapper.Plus
using Z.Dapper.Plus;

public void CustomBulkUpdate<T>(List<T> entities, List<string> propertyNames) where T : class
{
	var context = new DapperPlusContext();
	
	propertyNames.ForEach(x =>
	{
		context.Entity<T>().Map(x);
	});
	
	context.BulkUpdate(entities);
}

Date Modified: 2025-08-19
Author:

Edit this page in GitHub

Got any Dapper Question?