EfCore.BulkOperations 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package EfCore.BulkOperations --version 1.0.1                
NuGet\Install-Package EfCore.BulkOperations -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EfCore.BulkOperations" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EfCore.BulkOperations --version 1.0.1                
#r "nuget: EfCore.BulkOperations, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EfCore.BulkOperations as a Cake Addin
#addin nuget:?package=EfCore.BulkOperations&version=1.0.1

// Install EfCore.BulkOperations as a Cake Tool
#tool nuget:?package=EfCore.BulkOperations&version=1.0.1                

EfCore.BulkOperations

EfCore.BulkOperations enables bulk operations like BulkInsert, BulkUpdate, BulkDelete, and BulkMerge. While most operations use simple SQL queries, BulkMerge requires a more complex approach.

EfCore.BulkOperations Mapping columns from unique keys. You can configure custom column mapping if needed.

Go to NuGet


Quality Gate Status Coverage Reliability Rating Security Rating

Example

Bulk Insert

var items = new List<Product> { new Product("Product1", 100m) };
await _dbContext.BulkInsertAsync(items);
var items = new List<Product> { new Product("Product1", 100m) };
await _dbContext.BulkInsertAsync(
    items, 
    option => { option.IgnoreOnInsert = x => new { x.CreatedAt }; }
);

Bulk Update

var items = new List<Product> { new Product("Product1", 100m) };
await _dbContext.BulkUpdateAsync(items);
var items = new List<Product> { new Product("Product1", 100m) };
await _dbContext.BulkUpdateAsync(
    items, 
    option => { option.IgnoreOnUpdate = x => new { x.CreatedAt }; }
);
var items = new List<Product> { new Product("Product1", 100m) };
await _dbContext.BulkUpdateAsync(
    items, 
    option => { option.UniqueKeys = x => new { x.Id }; }
);

Bulk Delete

var items = new List<Product> { new Product("Product1", 100m) };
await _dbContext.BulkDeleteAsync(items);
var items = new List<Product> { new Product("Product1", 100m) };
await _dbContext.BulkDeleteAsync(
    items, 
    option => { option.UniqueKeys = x => new { x.Id }; }
);

Bulk Merge (MySql only)

Do not use BulkMergeAsync with other databases; it relies on a MySQL-specific query.

var items = new List<Product> { new Product("Product1", 100m) };
await _dbContext.BulkMergeAsync(items);
await _dbContext.BulkMergeAsync(
    items,
    option =>
    {
        option.IgnoreOnInsert = x => new { x.CreatedAt };
        option.IgnoreOnUpdate = x => new { x.CreatedAt };
    });

Working with Global Transaction

EfCore.BulkOperations utilizes local transactions within bulk processes. If you require manual transaction control, you can pass an existing transaction into the bulk process.

var connection = _dbContext.Database.GetDbConnection();
DbTransaction? transaction = null;
try
{
    transaction = await connection.BeginTransactionAsync();
    var insertItems = new List<Product> { new Product("Product1", 100m) };
    await _dbContext.BulkInsertAsync(insertItems, null, transaction);
    var updateItems = new List<Product> { new Product("Product2", 200m) };
    await _dbContext.BulkUpdateAsync(updateItems, null, transaction);
    await transaction.CommitAsync();
}
catch (Exception e)
{
    if (transaction is not null) await transaction.RollbackAsync();
}
finally
{
    if(transaction is not null) await transaction.DisposeAsync();
    await connection.CloseAsync();
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.4.1 86 8/5/2024
1.3.0 108 5/20/2024
1.2.0 107 5/10/2024
1.1.1 101 5/9/2024
1.1.0 119 5/7/2024
1.0.1 121 5/7/2024
1.0.0 112 5/6/2024