PhenX.EntityFrameworkCore.BulkInsert.SqlServer 0.1.0

There is a newer version of this package available.
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
                    
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="PhenX.EntityFrameworkCore.BulkInsert.SqlServer" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PhenX.EntityFrameworkCore.BulkInsert.SqlServer" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="PhenX.EntityFrameworkCore.BulkInsert.SqlServer" />
                    
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 PhenX.EntityFrameworkCore.BulkInsert.SqlServer --version 0.1.0
                    
#r "nuget: PhenX.EntityFrameworkCore.BulkInsert.SqlServer, 0.1.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 PhenX.EntityFrameworkCore.BulkInsert.SqlServer@0.1.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=PhenX.EntityFrameworkCore.BulkInsert.SqlServer&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=PhenX.EntityFrameworkCore.BulkInsert.SqlServer&version=0.1.0
                    
Install as a Cake Tool

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

  1. 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()
        ;
});
  1. Use the bulk insert extension method:
// Asynchronously
await dbContext.ExecuteBulkInsertAsync(entities);

// Or synchronously
dbContext.ExecuteBulkInsert(entities);
  1. 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
});
  1. You can also return the inserted entities (slower):
await dbContext.ExecuteBulkInsertReturnEntitiesAsync(entities);

Roadmap

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 :

SQL Server results with 500 000 rows :

bench-sqlserver.png

PostgreSQL results with 500 000 rows :

bench-postgresql.png

SQLite results with 500 000 rows :

bench-sqlite.png

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 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. 
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
0.4.1 136 7/16/2025
0.4.0 126 6/22/2025
0.3.2 199 6/8/2025
0.3.1 110 6/7/2025
0.3.0 145 6/2/2025
0.2.3 358 5/26/2025
0.2.2 142 5/26/2025
0.2.1 130 5/24/2025
0.2.0 73 5/24/2025
0.1.0 149 5/22/2025
0.0.3 168 5/20/2025
0.0.2 143 5/20/2025
0.0.1 154 5/20/2025