Skip to main content

BulkOperations.Package

A .NET library for efficient bulk insert, update, and merge operations against SQL Server.

Open Source · 2024 — 2026 · Author & Maintainer

Technology

  • C#
  • .NET
  • SQL Server
  • SqlBulkCopy
  • NuGet

Overview

Entity Framework's `AddRangeAsync` is fine until you're inserting a hundred thousand rows and it isn't anymore. BulkOperations.Package exists for that moment — an open-source C# library for inserting, updating, and merging large SQL Server datasets without the ORM overhead getting in the way.

It leans on SqlBulkCopy and table-valued parameters behind a fluent API, so the high-throughput path stays fast without forcing raw ADO.NET on every call site.

BulkMerge is the operation most libraries in this space get wrong or skip entirely — an upsert that has to decide, per row, whether it's an insert or an update, without round-tripping to the database once per row to check. It does that with a staging table and a single `MERGE` statement, so a 50,000-row upsert is one query, not 50,000.

The challenge

Problem: EF Core's change tracker is not built for bulk workloads — inserting or updating tens of thousands of entities through DbContext.SaveChangesAsync() means the change tracker has to track every entity individually, which is where the memory and time overhead comes from, not the database round-trip itself.

Approach: Bypassed the change tracker entirely for bulk paths: entities go straight into a SqlBulkCopy stream (inserts) or a staging table merged via a single MERGE statement (updates/upserts), with column mapping derived from entity property reflection so callers don't have to hand-write a mapping for every type.

Result: Bulk inserts that used to take minutes through EF Core's default path complete in seconds via SqlBulkCopy, and the library is published on NuGet where other .NET developers can install it directly rather than writing their own SqlBulkCopy wrapper from scratch.

Key features

  • High-volume data operations via a fluent BulkInsert, BulkUpdate, and BulkMerge API
  • Automatic SQL Server column mapping from entity properties and data annotations
  • Single-statement MERGE-based upserts via a staging table, avoiding per-row round-trips
  • Transaction-safe execution with configurable batch sizes and timeout handling
  • Support for strongly typed collections and dynamic data tables
  • Reusable application infrastructure with no third-party dependencies

← All projects