PhenX.EntityFrameworkCore.BulkInsert.SqlServer
0.1.0
See the version list below for details.
dotnet add package PhenX.EntityFrameworkCore.BulkInsert.SqlServer --version 0.1.0
NuGet\Install-Package PhenX.EntityFrameworkCore.BulkInsert.SqlServer -Version 0.1.0
<PackageReference Include="PhenX.EntityFrameworkCore.BulkInsert.SqlServer" Version="0.1.0" />
<PackageVersion Include="PhenX.EntityFrameworkCore.BulkInsert.SqlServer" Version="0.1.0" />
<PackageReference Include="PhenX.EntityFrameworkCore.BulkInsert.SqlServer" />
paket add PhenX.EntityFrameworkCore.BulkInsert.SqlServer --version 0.1.0
#r "nuget: PhenX.EntityFrameworkCore.BulkInsert.SqlServer, 0.1.0"
#:package PhenX.EntityFrameworkCore.BulkInsert.SqlServer@0.1.0
#addin nuget:?package=PhenX.EntityFrameworkCore.BulkInsert.SqlServer&version=0.1.0
#tool nuget:?package=PhenX.EntityFrameworkCore.BulkInsert.SqlServer&version=0.1.0
PhenX.EntityFrameworkCore.BulkInsert
A high-performance, provider-agnostic bulk insert extension for Entity Framework Core 8+. Supports SQL Server, PostgreSQL, SQLite.
Its main purpose is to provide a fast way to perform simple bulk inserts in Entity Framework Core applications.
Why this library?
- Performance: It is designed to be fast and memory efficient, making it suitable for high-performance applications.
- Provider-agnostic: It works with multiple database providers (SQL Server, PostgreSQL, and SQLite), allowing you to use it in different environments without changing your code.
- Simplicity: The API is simple and easy to use, making it accessible for developers of all skill levels.
For now, it does not support navigation properties, complex types, owned types, shadow properties, or inheritance, but they are in the roadmap.
Installation
Install the NuGet package for your database provider:
# For SQL Server
Install-Package PhenX.EntityFrameworkCore.BulkInsert.SqlServer
# For PostgreSQL
Install-Package PhenX.EntityFrameworkCore.BulkInsert.PostgreSql
# For SQLite
Install-Package PhenX.EntityFrameworkCore.BulkInsert.Sqlite
Usage
- Register the bulk insert provider in your
DbContextOptions
:
services.AddDbContext<MyDbContext>(options =>
{
options
// .UseSqlServer(connectionString) // or UseNpgsql or UseSqlite, as appropriate
.UseBulkInsertPostgreSql()
// OR
.UseBulkInsertSqlServer()
// OR
.UseBulkInsertSqlite()
;
});
- Use the bulk insert extension method:
// Asynchronously
await dbContext.ExecuteBulkInsertAsync(entities);
// Or synchronously
dbContext.ExecuteBulkInsert(entities);
- Optionally, you can configure the bulk insert options:
await dbContext.ExecuteBulkInsertAsync(entities, options =>
{
options.BatchSize = 1000; // Set the batch size for the insert operation, the default value is different for each provider
});
- You can also return the inserted entities (slower):
await dbContext.ExecuteBulkInsertReturnEntitiesAsync(entities);
Roadmap
- Add support for navigation properties
- Add support for complex types
- Add support for owned types
- Add support for shadow properties
- Add support for TPT (Table Per Type) inheritance
- Add support for TPC (Table Per Concrete Type) inheritance
- Add support for TPH (Table Per Hierarchy) inheritance
Benchmarks
Benchmark projects are available in the tests/PhenX.EntityFrameworkCore.BulkInsert.Benchmark
directory.
Run them to compare performance with raw bulk insert methods and other libraries (https://github.com/borisdj/EFCore.BulkExtensions
and https://entityframework-extensions.net/bulk-extensions), using optimized configuration (local Docker is required).
Legend :
PhenX_EntityFrameworkCore_BulkInsert
: this libraryRawInsert
: no library, using the native provider API (SqlBulkCopy for SQL Server, BeginBinaryImport for PostgreSQL, raw inserts for SQLite)Z_EntityFramework_Extensions_EFCore
: https://entityframework-extensions.net/bulk-extensionsEFCore_BulkExtensions
: https://github.com/borisdj/EFCore.BulkExtensionsEFCore_SaveChanges
: EF Core SaveChanges classic method
SQL Server results with 500 000 rows :
PostgreSQL results with 500 000 rows :
SQLite results with 500 000 rows :
Contributing
Contributions are welcome! Please open issues or submit pull requests for bug fixes, features, or documentation improvements.
License
MIT License. See LICENSE for details.
Product | Versions 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. 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. |
-
net8.0
- JetBrains.Annotations (>= 2024.3.0)
- Microsoft.EntityFrameworkCore.SqlServer (>= 8.0.16)
- PhenX.EntityFrameworkCore.BulkInsert (>= 0.1.0)
-
net9.0
- JetBrains.Annotations (>= 2024.3.0)
- Microsoft.EntityFrameworkCore.SqlServer (>= 9.0.5)
- PhenX.EntityFrameworkCore.BulkInsert (>= 0.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.