|
| 1 | +# EntityFrameworkCore.ExecuteInsert |
| 2 | + |
| 3 | +A high-performance, provider-agnostic bulk insert extension for Entity Framework Core. Supports SQL Server, PostgreSQL, SQLite. |
| 4 | + |
| 5 | +## Features |
| 6 | +- Very fast bulk insert support for multiple database providers |
| 7 | +- Supports SQL Server, PostgreSQL, and SQLite |
| 8 | +- Simple and intuitive API |
| 9 | +- Benchmarking and test projects included |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +Install the NuGet package for your database provider: |
| 14 | + |
| 15 | +```shell |
| 16 | +# For SQL Server |
| 17 | +Install-Package EntityFrameworkCore.ExecuteInsert.SqlServer |
| 18 | + |
| 19 | +# For PostgreSQL |
| 20 | +Install-Package EntityFrameworkCore.ExecuteInsert.PostgreSql |
| 21 | + |
| 22 | +# For SQLite |
| 23 | +Install-Package EntityFrameworkCore.ExecuteInsert.Sqlite |
| 24 | +``` |
| 25 | + |
| 26 | +## Usage |
| 27 | + |
| 28 | +1. Register the bulk insert provider in your `DbContextOptions`: |
| 29 | + |
| 30 | +```csharp |
| 31 | +services.AddDbContext<MyDbContext>(options => |
| 32 | +{ |
| 33 | + options |
| 34 | + .UseSqlServer(connectionString) // or UseNpgsql or UseSqlite, as appropriate |
| 35 | + .UseBulkInsert(); // <<< The important part |
| 36 | +}); |
| 37 | +``` |
| 38 | + |
| 39 | +2. Use the bulk insert extension method: |
| 40 | + |
| 41 | +```csharp |
| 42 | +await dbContext.ExecuteInsertAsync(entities); |
| 43 | +``` |
| 44 | + |
| 45 | +3. Optionally, you can configure the bulk insert options: |
| 46 | + |
| 47 | +```csharp |
| 48 | +await dbContext.ExecuteInsertAsync(entities, options => |
| 49 | +{ |
| 50 | + options.BatchSize = 1000; // Set the batch size for the insert operation, the default value is different for each provider |
| 51 | +}); |
| 52 | +``` |
| 53 | + |
| 54 | +4. You can also return the inserted entities (slower): |
| 55 | + |
| 56 | +```csharp |
| 57 | +await dbContext.ExecuteInsertWithIdentityAsync(entities, options => {}); |
| 58 | +``` |
| 59 | + |
| 60 | +## Benchmarks |
| 61 | +Benchmark projects are available in the [`tests/EntityFrameworkCore.ExecuteInsert.Benchmark`](tests/EntityFrameworkCore.ExecuteInsert.Benchmark/LibComparator.cs) directory. |
| 62 | +Run them to compare performance with other libraries (https://github.com/videokojot/EFCore.BulkExtensions.MIT and https://entityframework-extensions.net/bulk-extensions), |
| 63 | +using optimized configuration (local Docker is required). |
| 64 | + |
| 65 | +There is no need to compare with basic EF Core SaveChangesAsync, as it is significantly slower. |
| 66 | + |
| 67 | +SQL Server results : |
| 68 | + |
| 69 | + |
| 70 | +PostgreSQL results : |
| 71 | + |
| 72 | + |
| 73 | +SQLite results : |
| 74 | + |
| 75 | + |
| 76 | +## Contributing |
| 77 | +Contributions are welcome! Please open issues or submit pull requests for bug fixes, features, or documentation improvements. |
| 78 | + |
| 79 | +## License |
| 80 | +MIT License. See [LICENSE](LICENSE) for details. |
0 commit comments