MB.GenericBulkInsert 9.0.3

dotnet add package MB.GenericBulkInsert --version 9.0.3
                    
NuGet\Install-Package MB.GenericBulkInsert -Version 9.0.3
                    
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="MB.GenericBulkInsert" Version="9.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MB.GenericBulkInsert" Version="9.0.3" />
                    
Directory.Packages.props
<PackageReference Include="MB.GenericBulkInsert" />
                    
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 MB.GenericBulkInsert --version 9.0.3
                    
#r "nuget: MB.GenericBulkInsert, 9.0.3"
                    
#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.
#addin nuget:?package=MB.GenericBulkInsert&version=9.0.3
                    
Install MB.GenericBulkInsert as a Cake Addin
#tool nuget:?package=MB.GenericBulkInsert&version=9.0.3
                    
Install MB.GenericBulkInsert as a Cake Tool

MB.GenericBulkInsert NuGet Package

Overview

MB.GenericBulkInsert library allows you to perform fast and high-performance Bulk Insert operations on SQL Server using Entity Framework Core (EF Core).

Features

  • Fast and Efficient: Uses SqlBulkCopy to quickly insert large datasets.
  • Full EF Core Compatibility: Easily integrated into your EF Core DbContext.
  • Transaction Support: Database operations are wrapped in a transaction for rollback in case of failure.
  • Easy to Use: Perform bulk insert with just a few lines of code.

Getting Started

Installation

To integrate MB.GenericBulkInsert into your project, install it via the NuGet package manager:

Install-Package MB.GenericBulkInsert

Or through the .NET CLI:

dotnet add package MB.GenericBulkInsert

🛠 Usage

1️ Define Your EF Core Model

First, define your data model:

public class Product
{
    public int Id { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
}

2️ Define Your DbContext

Create a DbContext:

public class AppDbContext : DbContext
{
    public DbSet<Product> Products { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlServer("Server=.;Database=BulkInsertDB;Trusted_Connection=True;");
    }
}

3️ Use Bulk Insert

You can now use the Bulk Insert method as shown below:

using var context = new AppDbContext();

// 📌 Create 100,000 products
var products = Enumerable.Range(1, 100_000)
    .Select(i => new Product { Name = $"Product {i}", Price = i * 1.5m })
    .ToList();

// 📌 Call Bulk Insert
await context.BulkInsertAsync(products);

Console.WriteLine("Bulk insert completed!");

⚡ Performance

Method 10,000 Records (ms) 100,000 Records (ms)
AddRangeAsync() + SaveChangesAsync() 8500ms 85,000ms (85s)
BulkInsertAsync() (This Library) 450ms 4200ms (4.2s)

BulkInsertAsync is up to 20 times faster than EF Core's default method!

🔧 Configuration

You can customize the batch size to optimize performance based on the size of the data being inserted:

await context.BulkInsertAsync(products, batchSize: 10000); // Batch size of 10,000

📜 License

The MB.GenericBulkInsert library is licensed under the MIT License.

🙌 Contributing

If you'd like to contribute to this project, feel free to open a pull request.
For any questions or suggestions, please use the Issues section.

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. 
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
9.0.3 452 3/26/2025

- Added the **MB.GenericBulkInsert** library for efficient bulk data insertion using Entity Framework Core.
- Supports SQL Server databases for bulk insert operations.
- Provides an easy-to-use extension method for bulk inserting large datasets with configurable batch sizes.
- Optimized for performance in mass data operations