LLS.EFBulkExtensions
1.2.0
dotnet add package LLS.EFBulkExtensions --version 1.2.0
NuGet\Install-Package LLS.EFBulkExtensions -Version 1.2.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="LLS.EFBulkExtensions" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LLS.EFBulkExtensions" Version="1.2.0" />
<PackageReference Include="LLS.EFBulkExtensions" />
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 LLS.EFBulkExtensions --version 1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LLS.EFBulkExtensions, 1.2.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 LLS.EFBulkExtensions@1.2.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=LLS.EFBulkExtensions&version=1.2.0
#tool nuget:?package=LLS.EFBulkExtensions&version=1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
LLS.EFBulkExtensions
[English] | Português
High-performance extensions for EF Core 9 bulk operations: insert, update and delete with large volumes, batch processing, SQL Server and PostgreSQL support, type conversions, owned types, and optional returning of generated IDs.
Features
- Bulk insert, update and delete via DbContext extension methods
- Batch processing (BatchSize) and timeout control
- Support for SQL Server (SqlBulkCopy/MERGE) and PostgreSQL (binary COPY)
- Optional returning of generated IDs on inserts
- Handling properties with conversions (e.g., EnumToString) and owned types
- Optional internal transaction and extra configuration via model annotations
Compatibility and Dependencies
- .NET: net9.0
- EF Core 9.0 (Relational)
- Providers:
- SQL Server: Microsoft.Data.SqlClient
- PostgreSQL: Npgsql See project LLS.EFBulkExtensions.csproj.
Installation
- Local project: add a ProjectReference to
src/LLS.EFBulkExtensions. - NuGet (if published): reference the
LLS.EFBulkExtensionspackage and ensure:- SQL Server:
Microsoft.EntityFrameworkCore.SqlServer - PostgreSQL:
Npgsql.EntityFrameworkCore.PostgreSQL
- SQL Server:
Quick Start
Import the extensions and call the methods from your DbContext:
using LLS.EFBulkExtensions.Extensions;
using LLS.EFBulkExtensions.Options;
SQL Server:
var options = new DbContextOptionsBuilder<AppDbContext>()
.UseSqlServer("<your-connection-string>")
.Options;
PostgreSQL:
var options = new DbContextOptionsBuilder<AppDbContext>()
.UseNpgsql("<your-connection-string>")
.Options;
Insert:
await context.BulkInsertAsync(entities, new BulkInsertOptions {
ReturnGeneratedIds = false,
BatchSize = 10_000,
TimeoutSeconds = 120,
PreserveIdentity = false,
UseInternalTransaction = false,
KeepNulls = false,
UseAppLock = false
});
Update:
await context.BulkUpdateAsync(entitiesToUpdate, new BulkUpdateOptions {
BatchSize = 10_000,
TimeoutSeconds = 120,
UseInternalTransaction = false
});
Delete:
await context.BulkDeleteAsync(entitiesToDelete, new BulkDeleteOptions {
BatchSize = 10_000,
TimeoutSeconds = 120,
UseInternalTransaction = false
});
Options
- BulkInsertOptions: file
- ReturnGeneratedIds, BatchSize, TimeoutSeconds, PreserveIdentity, UseInternalTransaction, KeepNulls, UseAppLock
- BulkUpdateOptions: file
- BatchSize, TimeoutSeconds, UseInternalTransaction
- BulkDeleteOptions: file
- BatchSize, TimeoutSeconds, UseInternalTransaction
You can also configure annotations directly on the model for insert:
builder.Property(p => p.Id).ValueGeneratedOnAdd(ReturnGeneratedIds: true, BatchSize: 10000);
Extension: SequenceModelExtensions.
Database Support
- SQL Server: SqlServerBulkInserter, SqlServerBulkUpdater, SqlServerBulkDeleter
- PostgreSQL: PostgresBulkInserter, PostgresBulkUpdater, PostgresBulkDeleter
How It Works
- Insert:
- SQL Server: uses SqlBulkCopy for staging and MERGE with OUTPUT when needed to return IDs.
- PostgreSQL: uses binary COPY; when requested, inserts into a temporary table and returns IDs via INSERT ... RETURNING.
- Update: creates a temporary table, bulk loads into temp and applies UPDATE with JOIN on PK, ignoring ValueGenerated columns.
- Delete: creates a temporary table and applies DELETE with JOIN on PK. Data construction: DataTableBuilder maps properties, types, conversions (includes EnumToString) and owned types.
Full Examples
- SQL Server: BulkInsertConsoleStyleTests.cs
- PostgreSQL: BulkInsertConsoleStyleTests.cs
Requirements
- EF Core 9 with correct entity mapping (table, schema, PK)
- To return IDs on inserts, use PK with
ValueGeneratedOnAddand optionally annotateReturnGeneratedIdsvia model
APIs
- Inserts: BulkInsertAsync
- Updates: BulkUpdateAsync
- Deletes: BulkDeleteAsync
Notes
- BatchSize and Timeout configurable via options and annotations
- Optional internal transaction
- Support for PreserveIdentity and KeepNulls on insert
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. 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 is compatible. 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.
-
net10.0
- Microsoft.Data.SqlClient (>= 6.1.3)
- Microsoft.EntityFrameworkCore (>= 10.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.0)
- Npgsql (>= 8.0.3)
-
net5.0
- Microsoft.Data.SqlClient (>= 6.1.3)
- Microsoft.EntityFrameworkCore (>= 5.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 5.0.0)
- Npgsql (>= 8.0.3)
-
net6.0
- Microsoft.Data.SqlClient (>= 6.1.3)
- Microsoft.EntityFrameworkCore (>= 6.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 6.0.0)
- Npgsql (>= 8.0.3)
-
net7.0
- Microsoft.Data.SqlClient (>= 6.1.3)
- Microsoft.EntityFrameworkCore (>= 7.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 7.0.0)
- Npgsql (>= 8.0.3)
-
net8.0
- Microsoft.Data.SqlClient (>= 6.1.3)
- Microsoft.EntityFrameworkCore (>= 8.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.0)
- Npgsql (>= 8.0.3)
-
net9.0
- Microsoft.Data.SqlClient (>= 6.1.3)
- Microsoft.EntityFrameworkCore (>= 9.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 9.0.0)
- Npgsql (>= 8.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.