SqlServerBulkInsert 2.0.0

dotnet add package SqlServerBulkInsert --version 2.0.0
                    
NuGet\Install-Package SqlServerBulkInsert -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SqlServerBulkInsert" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SqlServerBulkInsert" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SqlServerBulkInsert" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SqlServerBulkInsert --version 2.0.0
                    
#r "nuget: SqlServerBulkInsert, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SqlServerBulkInsert@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SqlServerBulkInsert&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SqlServerBulkInsert&version=2.0.0
                    
Install as a Cake Tool

SqlServerBulkInsert: SQL Server Bulk Copy for .NET

SqlServerBulkInsert is a lightweight, database-centric library for performing high-speed bulk inserts into Microsoft SQL Server. It provides a functional, fluent wrapper around the native SqlBulkCopy API using a custom IDataReader adapter to stream data directly from your domain models.

This library follows the design philosophy of my other libraries, moving away from application language-centric abstractions to a Database-first approach where the mapping is defined by the SQL types of your destination table.

Setup

SqlServerBulkInsert is available on NuGet.

You can add the following dependency to your .csproj to include it in your project:

<PackageReference Include="SqlServerBulkInsert" Version="2.0.0" />

Key Features

  • Stateless Mappers: Define your schema mapping once and reuse it across multiple writers or threads.
  • Database-First API: Mapping is driven by SQL Server types (e.g., NVarChar, DateTimeOffset, Int), ensuring correct metadata for the driver.
  • Automatic Bracketing: Automatic escaping of schema, table, and column names using [] to prevent conflicts with reserved keywords. Handles optional schemas gracefully.
  • Zero-Allocation Streaming: Uses a custom IDataReader bridge to pull data lazily from IEnumerable<T>, keeping memory consumption flat.
  • AOT Ready: Fully compatible with Native AOT and trimming in modern .NET.

Quick Start

1. Define your Data Model

Works seamlessly with C# records, structs, or traditional classes.

public record SensorData(
    Guid Id,
    string Name,
    int Temperature,
    decimal SignalStrength,
    DateTimeOffset Timestamp
);

2. Define your Mapping (Stateless & Thread-Safe)

The SqlServerMapper<T> defines the structure. It is stateless and should be instantiated once as a singleton.

private static readonly SqlServerMapper<SensorData> Mapper = 
    new SqlServerMapper<SensorData>()
        .Map("Id", SqlServerTypes.UniqueIdentifier, x => x.Id)
        .Map("Name", SqlServerTypes.NVarChar, x => x.Name)
        // Automatic handling of primitives and nullable structs
        .Map("Temperature", SqlServerTypes.Int, x => x.Temperature)
        .Map("Signal", SqlServerTypes.Decimal, x => x.SignalStrength)
        .Map("Timestamp", SqlServerTypes.DateTimeOffset, x => x.Timestamp);

3. Execute the Bulk Insert

The SqlServerBulkWriter<T> executes the bulk copy operation.

public async Task SaveDataAsync(SqlConnection conn, IEnumerable<SensorData> data)
{
    var writer = new SqlServerBulkWriter<SensorData>(Mapper)
        .WithBatchSize(5000);

    await writer.WriteAllAsync(conn, "dbo", "Sensors", data);
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.0.0 34 3/25/2026
1.0.0 2,955 5/5/2018
0.1.0 2,625 10/15/2016