MB.GenericBulkInsert
9.0.3
dotnet add package MB.GenericBulkInsert --version 9.0.3
NuGet\Install-Package MB.GenericBulkInsert -Version 9.0.3
<PackageReference Include="MB.GenericBulkInsert" Version="9.0.3" />
<PackageVersion Include="MB.GenericBulkInsert" Version="9.0.3" />
<PackageReference Include="MB.GenericBulkInsert" />
paket add MB.GenericBulkInsert --version 9.0.3
#r "nuget: MB.GenericBulkInsert, 9.0.3"
#addin nuget:?package=MB.GenericBulkInsert&version=9.0.3
#tool nuget:?package=MB.GenericBulkInsert&version=9.0.3
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.
π Links
π 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 | 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. |
-
net9.0
- Microsoft.EntityFrameworkCore (>= 9.0.3)
- Microsoft.EntityFrameworkCore.Relational (>= 9.0.3)
- Microsoft.EntityFrameworkCore.SqlServer (>= 9.0.3)
- System.Data.SqlClient (>= 4.9.0)
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 | 12 days ago |
- 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