EFBatch 1.0.0
dotnet add package EFBatch --version 1.0.0
NuGet\Install-Package EFBatch -Version 1.0.0
<PackageReference Include="EFBatch" Version="1.0.0" />
<PackageVersion Include="EFBatch" Version="1.0.0" />
<PackageReference Include="EFBatch" />
paket add EFBatch --version 1.0.0
#r "nuget: EFBatch, 1.0.0"
#:package EFBatch@1.0.0
#addin nuget:?package=EFBatch&version=1.0.0
#tool nuget:?package=EFBatch&version=1.0.0
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
orSaveChangesAsync
, 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
orSaveChangesAsync
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 | Versions 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. |
-
net9.0
- Microsoft.EntityFrameworkCore (>= 9.0.6)
- Microsoft.EntityFrameworkCore.Relational (>= 9.0.6)
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.