Skip to content

Swevo/EFCore.BulkOperations

Repository files navigation

EFCore.BulkOperations

NuGet NuGet Downloads CI License: MIT

Free, MIT-licensed bulk insert/update/delete for EF Core. No commercial license required — ever.

Why EFCore.BulkOperations?

SaveChangesAsync sends one round trip per row, which falls over once you need to insert thousands of entities at a time. Commercial libraries like Z.EntityFramework.Extensions solve this well but require a paid license per developer/server. EFCore.BulkOperations gives you the same core capability — high-throughput bulk insert, plus update/delete — fully free and open source under MIT.

using EFCore.BulkOperations;

await dbContext.BulkInsertAsync(orders);

await dbContext.Orders
    .Where(o => o.Status == OrderStatus.Pending)
    .BulkUpdateAsync(setters => setters.SetProperty(o => o.Status, OrderStatus.Cancelled));

await dbContext.Orders
    .Where(o => o.CreatedAt < cutoff)
    .BulkDeleteAsync();

Install

dotnet add package Swevo.EFCore.BulkOperations

How it works

  • BulkInsertAsync — on SQL Server, streams entities straight into SqlBulkCopy (no intermediate DataTable, no per-row SaveChanges round trip). On every other provider (SQLite, InMemory, Npgsql, etc.) it automatically falls back to chunked AddRange + SaveChangesAsync batches with ChangeTracker.Clear() between batches, so the same call works everywhere — just faster on SQL Server.
  • BulkUpdateAsync / BulkDeleteAsync — thin, discoverable wrappers around EF Core's native ExecuteUpdateAsync/ExecuteDeleteAsync, rounding out the bulk-operations API surface under one consistent name.
  • Database-generated columns (identity primary keys, computed columns) are automatically excluded from the insert payload — set BulkInsertOptions.ExcludeDatabaseGeneratedColumns = false to override.
await dbContext.BulkInsertAsync(orders, new BulkInsertOptions
{
    BatchSize = 5000,
    TimeoutSeconds = 60,
});

Roadmap

  • BulkInsertOrUpdateAsync (upsert/merge) is planned for a future 1.1 release. It's deliberately out of scope for 1.0 to ship a well-tested, focused insert/update/delete core first.

Design goals

  • MIT licensed, forever. No commercial tier, no per-seat fees.
  • Same API everywhere. SQL Server gets SqlBulkCopy performance; every other provider gets a correct, tested fallback — you don't need #if branches in your app code.
  • No hard SqlClient dependency at runtime for non-SQL-Server apps — the SQL Server path is only exercised when DbContext.Database.ProviderName reports the SQL Server provider.

Related Packages

Package Downloads Description
Swevo.EFCore.Outbox Downloads Transactional outbox pattern for EF Core + AutoBus
Swevo.EFCore.StronglyTyped Downloads Compile-time strongly-typed ID generation for
Swevo.EFCore.SoftDelete Downloads Compile-time soft-delete generation for EF Core entities using Roslyn source generators
Swevo.EFCore.Seeding Downloads Fluent, idempotent, dependency-ordered seed data for EF Core
Swevo.EFCore.Pagination Downloads Offset and cursor-based pagination for EF Core
Swevo.EFCore.JsonColumn Downloads Compile-time JSON column configuration for EF Core 8+ — [JsonColumn] on owned navigation properties generates ConfigureJsonColumns(ModelBuilder) with OwnsOne(
Swevo.EFCore.MultiTenant Downloads Compile-time multi-tenancy for EF Core
Swevo.EFCore.RowVersion Downloads Compile-time optimistic concurrency for EF Core — [Optimistic] source generator adds RowVersion property, IOptimisticEntity, and SaveChangesClientWinsAsync / SaveChangesDatabaseWinsAsync retry extensions

💼 Need .NET consulting?

I'm the author of EFCore.BulkOperations and a suite of compile-time source generators (AutoWire, AutoMap.Generator) and 28+ Polly v8 resilience packages. I'm available for consulting on Polly v8 resilience, Azure cloud architecture, and clean .NET design.

→ solidqualitysolutions.com · LinkedIn

Also by the same author

🌐 Full suite overview: swevo.github.io

Package Description
FluentPdf Free, MIT-licensed fluent PDF generation — alternative to QuestPDF's commercial license.
AutoBus Free, MIT-licensed message bus — alternative to MassTransit's commercial license.
AutoArchitecture Free, MIT-licensed compile-time architecture rule enforcement — alternative to NDepend.
AutoAssert Free, MIT-licensed fluent assertions — alternative to FluentAssertions' commercial license.
AutoWire Compile-time DI auto-registration — [Scoped]/[Singleton]/[Transient] generates IServiceCollection registration code.
AutoMap.Generator Compile-time object mapping — [Map(typeof(Dto))] generates ToDto() extension methods.
EFCore.Outbox Transactional outbox pattern for EF Core.
AutoDispatch.Generator Compile-time CQRS dispatcher — free alternative to MediatR's commercial license.
PollyAnalyzers Free Roslyn analyzers for async/resilience anti-patterns — blocking calls, async void, fire-and-forget tasks, swallowed exceptions.
PollyAction Free retry/backoff GitHub Action — wrap any CI step with exponential-backoff retries.

License

MIT © Justin Bannister

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages