EFBatch 1.0.0

dotnet add package EFBatch --version 1.0.0
                    
NuGet\Install-Package EFBatch -Version 1.0.0
                    
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="EFBatch" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EFBatch" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="EFBatch" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EFBatch --version 1.0.0
                    
#r "nuget: EFBatch, 1.0.0"
                    
#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.
#:package EFBatch@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EFBatch&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=EFBatch&version=1.0.0
                    
Install as a Cake Tool

EFBatch - Entity Framework Core Batch Operations

EFBatch is an extension for Entity Framework Core that enables efficient batching of SQL commands such as bulk update, delete, and insert-from-query. It integrates seamlessly with EF Core's DbContext and transaction management, allowing you to execute multiple DML operations in a single database roundtrip.

Features

  • Batch Update: Update multiple records with a single SQL command.
  • Batch Delete: Delete multiple records efficiently.
  • Batch Insert From Query: Insert records into a table based on a LINQ query.
  • Transaction Support: All batch operations participate in the current transaction or create a new one if needed.
  • EF Core Integration: Works with EF Core's change tracking and SaveChanges/SaveChangesAsync flow.

Installation

Getting Started

1. Inherit from BatchingDbContext

public class HRContext : BatchingDbContext<HRContext>
{
    public HRContext(DbContextOptions<HRContext> options) : base(options)
    {

    }
// CODE REMOVED FOR BREVITY...
}

2. Usage Examples

Batch Delete
 _hrContext.BatchDelete(context => context.PositionRoleGroup.Where(x => x.PositionId == positionUpdateRequest.PositionId));
 await _hrContext.SaveChangesAsync();
Batch Update
  _hrContext.BatchUpdate(context => context.Position.Where(x => x.Id == positionUpdateRequest.PositionId),
      x => x.SetProperty(y => y.Name, positionUpdateRequest.Name));
await _hrContext.SaveChangesAsync();
Batch Insert From Query
 _hrContext.BatchInsertFromQuery(context =>
             context.Position
             .Where(x => !x.RoleGroups.Any(y => y.Id == rolegroupid))
             .Select(x => new PositionRoleGroup(x.Id, rolegroupid)));
await _hrContext.SaveChangesAsync();

How It Works

  • Batching: When you call a batch method (BatchUpdate, BatchDelete, BatchInsertFromQuery), the SQL command is intercepted and queued.
  • Execution: On SaveChanges or SaveChangesAsync, all batched commands are executed in a single transaction, followed by EF Core's normal change tracking operations.
  • Transactions: If a transaction is already open, batch commands participate in it. Otherwise, a new transaction is created.
  • Logging: Logging happens just the way EF core does.

API Reference

Notes

  • All batch operations are executed before EF Core's tracked changes are saved.
  • You must call SaveChanges or SaveChangesAsync to execute batched commands.
  • Batched commands are cleared after each save operation.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.0.0 124 8/10/2025

EFBatch is an extension for Entity Framework Core that enables efficient batching of SQL commands such as bulk update, delete, and insert-from-query. It integrates seamlessly with EF Core's DbContext and transaction management, allowing you to execute multiple DML operations in a single database roundtrip.