Skip to content

Commit 200cc0a

Browse files
author
fabien.menager
committed
Update readme for MySQL and the provider options
1 parent 7c337da commit 200cc0a

1 file changed

Lines changed: 40 additions & 3 deletions

File tree

README.md

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
# PhenX.EntityFrameworkCore.BulkInsert
22

3-
A high-performance, provider-agnostic bulk insert extension for Entity Framework Core 8+. Supports SQL Server, PostgreSQL, SQLite.
3+
A high-performance, provider-agnostic bulk insert extension for Entity Framework Core 8+. Supports SQL Server, PostgreSQL, SQLite and MySQL.
44

55
Its main purpose is to provide a fast way to perform simple bulk inserts in Entity Framework Core applications.
66

77
## Why this library?
88

99
- **Performance**: It is designed to be fast and memory efficient, making it suitable for high-performance applications.
10-
- **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.
10+
- **Provider-agnostic**: It works with multiple database providers (SQL Server, PostgreSQL, SQLite and MySQL), allowing you to use it in different environments without changing your code.
1111
- **Simplicity**: The API is simple and easy to use, making it accessible for developers of all skill levels.
1212

1313
For now, it does not support navigation properties, complex types, owned types, shadow properties, or inheritance,
1414
but they are in [the roadmap](#roadmap).
1515

16+
## Packages
17+
18+
| Package Name | Description | NuGet Link |
19+
|---------------------------------------------------|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
20+
| `PhenX.EntityFrameworkCore.BulkInsert.SqlServer` | For SQL Server | [![NuGet](https://img.shields.io/nuget/v/PhenX.EntityFrameworkCore.BulkInsert.SqlServer.svg)](https://www.nuget.org/packages/PhenX.EntityFrameworkCore.BulkInsert.SqlServer) |
21+
| `PhenX.EntityFrameworkCore.BulkInsert.PostgreSql` | For PostgreSQL | [![NuGet](https://img.shields.io/nuget/v/PhenX.EntityFrameworkCore.BulkInsert.PostgreSql.svg)](https://www.nuget.org/packages/PhenX.EntityFrameworkCore.BulkInsert.PostgreSql) |
22+
| `PhenX.EntityFrameworkCore.BulkInsert.Sqlite` | For SQLite | [![NuGet](https://img.shields.io/nuget/v/PhenX.EntityFrameworkCore.BulkInsert.Sqlite.svg)](https://www.nuget.org/packages/PhenX.EntityFrameworkCore.BulkInsert.Sqlite) |
23+
| `PhenX.EntityFrameworkCore.BulkInsert.MySql` | For MySql | [![NuGet](https://img.shields.io/nuget/v/PhenX.EntityFrameworkCore.BulkInsert.Sqlite.svg)](https://www.nuget.org/packages/PhenX.EntityFrameworkCore.BulkInsert.MySql) |
24+
| `PhenX.EntityFrameworkCore.BulkInsert` | Common library | [![NuGet](https://img.shields.io/nuget/v/PhenX.EntityFrameworkCore.BulkInsert.svg)](https://www.nuget.org/packages/PhenX.EntityFrameworkCore.BulkInsert) |
25+
1626
## Installation
1727

1828
Install the NuGet package for your database provider:
@@ -26,6 +36,9 @@ Install-Package PhenX.EntityFrameworkCore.BulkInsert.PostgreSql
2636

2737
# For SQLite
2838
Install-Package PhenX.EntityFrameworkCore.BulkInsert.Sqlite
39+
40+
# For MySql
41+
Install-Package PhenX.EntityFrameworkCore.BulkInsert.MySql
2942
```
3043

3144
## Usage
@@ -43,6 +56,8 @@ services.AddDbContext<MyDbContext>(options =>
4356
.UseBulkInsertSqlServer()
4457
// OR
4558
.UseBulkInsertSqlite()
59+
// OR
60+
.UseBulkInsertMySql()
4661
;
4762
});
4863
```
@@ -57,13 +72,35 @@ await dbContext.ExecuteBulkInsertAsync(entities);
5772
dbContext.ExecuteBulkInsert(entities);
5873
```
5974

60-
3. Optionally, you can configure the bulk insert options:
75+
3. You can also configure the bulk insert options:
6176

6277
```csharp
78+
// Common options
6379
await dbContext.ExecuteBulkInsertAsync(entities, options =>
6480
{
6581
options.BatchSize = 1000; // Set the batch size for the insert operation, the default value is different for each provider
6682
});
83+
84+
// Provider specific options, when available, example for SQL Server
85+
await dbContext.ExecuteBulkInsertAsync(entities, (SqlServerBulkInsertOptions o) => // <<< here specify the SQL Server options class
86+
{
87+
options.EnableStreaming = true; // Enable streaming for SQL Server
88+
});
89+
90+
// Provider specific options, supporting multiple providers
91+
await dbContext.ExecuteBulkInsertAsync(entities, o =>
92+
{
93+
o.MoveRows = true;
94+
95+
if (o is SqlServerBulkInsertOptions sqlServerOptions)
96+
{
97+
sqlServerOptions.EnableStreaming = true;
98+
}
99+
else if (o is MySqlBulkInsertOptions mysqlOptions)
100+
{
101+
mysqlOptions.BatchSize = 1000;
102+
}
103+
});
67104
```
68105

69106
4. You can also return the inserted entities (slower):

0 commit comments

Comments
 (0)