RepoDb.PostgreSql.BulkOperations 1.17.0-alpha1

Prefix Reserved
This is a prerelease version of RepoDb.PostgreSql.BulkOperations.
dotnet add package RepoDb.PostgreSql.BulkOperations --version 1.17.0-alpha1
                    
NuGet\Install-Package RepoDb.PostgreSql.BulkOperations -Version 1.17.0-alpha1
                    
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="RepoDb.PostgreSql.BulkOperations" Version="1.17.0-alpha1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RepoDb.PostgreSql.BulkOperations" Version="1.17.0-alpha1" />
                    
Directory.Packages.props
<PackageReference Include="RepoDb.PostgreSql.BulkOperations" />
                    
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 RepoDb.PostgreSql.BulkOperations --version 1.17.0-alpha1
                    
#r "nuget: RepoDb.PostgreSql.BulkOperations, 1.17.0-alpha1"
                    
#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 RepoDb.PostgreSql.BulkOperations@1.17.0-alpha1
                    
#: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=RepoDb.PostgreSql.BulkOperations&version=1.17.0-alpha1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=RepoDb.PostgreSql.BulkOperations&version=1.17.0-alpha1&prerelease
                    
Install as a Cake Tool

<div align="center"> <a href="https://repodb.net/tutorial/get-started-postgresql/"><image src="PostgreSQL.png" style="width:256px;" /></a> <br/> <span style="font-size:28px;font-weight:bold;"><a href="https://repodb.net/tutorial/get-started-postgresql/"><strong>RepoDb.PostgreSql.BulkOperations</strong></a></span> <br/> <span style="font-size:16px;">A high-performance data productivity platform for bulk operations on PostgreSQL in .NET.</span> </div>


<br/>

PostgreSqlBulkBuild PostgreSqlBulkHome PostgreSqlBulkVersion

RepoDb.PostgreSql.BulkOperations

A high-performant extension library of RepoDB that does bulk operations towards a PostgreSQL database. It uses PostgreSQL's native binary import protocol to load the data into the database.

The BinaryBulk* methods are obsolete. Use the Bulk* methods documented below instead — they replace the Binary variants one-for-one.

Important Pages

  • GitHub Home — core library and source code.
  • Website — full documentation, API reference, and blog.

Core Features

Community

License

Apache-2.0 — Copyright © 2020 Michael Camara Pendon


Installation

Install-Package RepoDb.PostgreSql.BulkOperations

Then initialize the bootstrapper once at application startup:

GlobalConfiguration
    .Setup()
    .UsePostgreSql();

Async Methods

Every synchronous operation has a corresponding Async overload.

BulkInsert

Inserts a list of entities into the database in bulk. Returns the number of inserted rows.

using (var connection = new NpgsqlConnection(ConnectionString))
{
    var customers = GetCustomers();
    var insertedRows = connection.BulkInsert<Customer>(customers);
}

Or via table-name:

using (var connection = new NpgsqlConnection(ConnectionString))
{
    var customers = GetCustomers();
    var insertedRows = connection.BulkInsert("Customer", customers);
}

Or via a DataTable:

using (var connection = new NpgsqlConnection(ConnectionString))
{
    var table = GetCustomersAsDataTable();
    var insertedRows = connection.BulkInsert("Customer", table);
}

Returning generated identities:

using (var connection = new NpgsqlConnection(ConnectionString))
{
    var customers = GetCustomers(); // Id not set
    connection.BulkInsert<Customer>(customers, identityBehavior: PostgreSqlBulkImportIdentityBehavior.ReturnIdentity);
    // customers[i].Id now holds the generated identity for each row
}

BulkMerge

Upserts a list of entities in bulk — inserts new rows and updates existing ones based on the defined qualifiers. Returns the number of affected rows.

using (var connection = new NpgsqlConnection(ConnectionString))
{
    var customers = GetCustomers();
    var mergedRows = connection.BulkMerge<Customer>(customers);
}

Or with qualifiers:

using (var connection = new NpgsqlConnection(ConnectionString))
{
    var customers = GetCustomers();
    var mergedRows = connection.BulkMerge<Customer>(customers, qualifiers: e => new { e.LastName, e.DateOfBirth });
}

Or via table-name with qualifiers:

using (var connection = new NpgsqlConnection(ConnectionString))
{
    var customers = GetCustomers();
    var mergedRows = connection.BulkMerge("Customer", customers, qualifiers: Field.From("LastName", "DateOfBirth"));
}

Or via a DataTable:

using (var connection = new NpgsqlConnection(ConnectionString))
{
    var table = GetCustomersAsDataTable();
    var mergedRows = connection.BulkMerge("Customer", table);
}

BulkUpdate

Updates existing rows in the database in bulk, matched by the defined qualifiers. Returns the number of updated rows.

using (var connection = new NpgsqlConnection(ConnectionString))
{
    var customers = GetCustomers();
    var rows = connection.BulkUpdate<Customer>(customers);
}

Or with qualifiers:

using (var connection = new NpgsqlConnection(ConnectionString))
{
    var customers = GetCustomers();
    var rows = connection.BulkUpdate<Customer>(customers, qualifiers: e => new { e.LastName, e.DateOfBirth });
}

Or via a DataTable:

using (var connection = new NpgsqlConnection(ConnectionString))
{
    var table = GetCustomersAsDataTable();
    var rows = connection.BulkUpdate("Customer", table);
}

BulkDelete

Deletes existing rows from the database in bulk, matched by the defined qualifiers. Returns the number of deleted rows.

using (var connection = new NpgsqlConnection(ConnectionString))
{
    var customers = GetCustomers();
    var deletedRows = connection.BulkDelete<Customer>(customers);
}

Or with qualifiers:

using (var connection = new NpgsqlConnection(ConnectionString))
{
    var customers = GetCustomers();
    var deletedRows = connection.BulkDelete<Customer>(customers, qualifiers: e => new { e.LastName, e.DateOfBirth });
}

Or via a DataTable:

using (var connection = new NpgsqlConnection(ConnectionString))
{
    var table = GetCustomersAsDataTable();
    var deletedRows = connection.BulkDelete("Customer", table);
}

BulkDeleteByKey

Deletes existing rows from the database in bulk, matched by their primary (or identity) key value alone — no entities or DataTable involved, just the list of key values to remove. Returns the number of deleted rows.

using (var connection = new NpgsqlConnection(ConnectionString))
{
    var primaryKeys = new [] { 10045, 10046, 10047 };
    var deletedRows = connection.BulkDeleteByKey("Customer", primaryKeys);
}

Column Mappings Behavior

When no mappings are passed to BinaryImport, BulkInsert, BulkMerge, BulkUpdate, or BulkDelete (or their async variants), the columns of the source (entities, DataTable, or DbDataReader) are aligned with the columns of the destination table based on the BulkColumnMappingsBehavior setting:

Value Column names must match Column order must match Destination columns missing from the source Source columns missing from the destination
Automatic (default) Only the matching ones No Bypassed Ignored
Strict Yes Yes Throws Throws
StrictBypass Yes No Bypassed Throws

Automatic is the default and is the behavior of the earlier versions. PostgreSqlBulkOperationsDbSetting inherits PostgreSqlDbSetting, and UsePostgreSql(...) registers it as the setting of the NpgsqlConnection in place of the default one. Strict and StrictBypass throw a PostgreSqlBulkColumnMappingsException (naming the offending columns) before any data is written.

GlobalConfiguration
    .Setup()
    .UsePostgreSql(new PostgreSqlBulkOperationsDbSetting
    {
        BulkColumnMappingsBehavior = PostgreSqlBulkColumnMappingsBehavior.StrictBypass
    });

For example, with a Customer table that has the Id, Name, Email, and CreatedDateUtc columns, and a DataTable source with the Email, Name, and Nickname columns:

  • Strict throws, because the order differs, Id/CreatedDateUtc are missing, and Nickname does not exist in the destination.
  • StrictBypass throws, because Nickname does not exist in the destination.
  • Automatic inserts Name and Email, and ignores Nickname.
try
{
    await connection.BulkInsertAsync("Customer", table);
}
catch (PostgreSqlBulkColumnMappingsException ex)
{
    // e.g. "... Source column(s) that do not exist on the destination table: 'Nickname'."
    logger.LogError(ex, "Bulk insert rejected due to column misalignment.");
    throw;
}

Explicitly passed mappings always take precedence: the setting is not applied to them. BulkDeleteByKey is not affected, as its source is a list of key values rather than a set of columns.

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 is compatible.  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 (2)

Showing the top 2 NuGet packages that depend on RepoDb.PostgreSql.BulkOperations:

Package Downloads
NBomber.Sinks.Timescale

NBomber sink that writes metrics data to TimescaleDB

Fx.Data.SQL

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.17.0-alpha1 36 10/2/2026
1.16.0 501 9/9/2026
1.16.0-beta2 112 8/15/2026
1.16.0-beta1 112 8/6/2026
1.16.0-alpha2 109 8/6/2026
1.16.0-alpha1 123 8/5/2026
1.15.0 1,261 7/18/2026
1.15.0-telemetry 123 7/18/2026
1.14.0 16,306 6/28/2026
1.13.2-alpha1 1,616 2/26/2024
1.13.1 278,363 3/16/2023
1.13.0 2,766 11/2/2022
1.3.2-alpha1 240 2/26/2024
0.0.12 910 10/25/2022
0.0.1-alpha2 118 8/5/2026
Loading failed