RepoDb.PostgreSql.BulkOperations 1.15.0

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

PostgreSqlBulkBuild PostgreSqlBulkHome PostgreSqlBulkVersion

RepoDb.PostgreSql.BulkOperations

High-performance bulk operations for RepoDB on PostgreSQL. Uses PostgreSQL's native binary import protocol to transfer data in a single pass — up to 90% faster than row-by-row or batch operations.

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:

RepoDb.PostgreSqlBootstrap.Initialize();

Or visit the installation page for more options.

Special Arguments

qualifiers — defines the fields used in the matching criteria for delete, merge, and update operations. Defaults to the primary key column.

keepIdentity — when enabled, the identity property value on the entity is preserved during the operation.

identityBehavior — controls identity handling and whether newly generated identity values are returned and written back to the entities.

pseudoTableType — controls whether a physical or session-scoped temporary table is created internally during the operation.

mergeCommandType — controls whether ON CONFLICT DO UPDATE or separate UPDATE/INSERT SQL commands are used during merge.

Identity Setting Alignment

RepoDB adds an internal __RepoDb_OrderColumn to the pseudo-temporary table when identity fields are present. This column preserves the original index of each entity in the IEnumerable<T> collection, ensuring generated identity values are mapped back to the correct objects after the operation completes.

BatchSize

All operations accept a batchSize argument to control how many rows are sent to the server per round-trip. Defaults to null (all rows in one pass). Tune this based on column count, data size, and network characteristics.

Enum Types

Npgsql supports the following .NET enum mappings:

  • .NET Enum → PostgreSQL text-based types (e.g. text, varchar)
  • .NET Enum → PostgreSQL integer types (e.g. int4, int8)
  • .NET Enum → Native PostgreSQL enum type, when mapped via NpgsqlDataSource.MapEnum()

These mappings work correctly with standard fluent operations such as Insert and InsertAll. However, bulk operations such as BinaryBulkInsert may fail with the following error when an enum property towards Native PostgreSQL enum type (item 3) is involved:

'RepoDb.PostgreSql.BulkOperations.IntegrationTests.Enumerations.Hands' is not supported for parameters having NpgsqlDbType 'Unknown'.

To fix this, you have to follow the steps below.

Use the NpgsqlDataSource.MapEnum() method to map the PostgreSQL enum type on the current data source. Use the NpgsqlDataSourceBuilder class and then use the connection object created from this builder.

var dataSource = new NpgsqlDataSourceBuilder(Database.ConnectionString)
	.MapEnum<Hands>("hand", new NpgsqlNullNameTranslator())
	.Build();
var connection = dataSource.CreateConnection();

// Do your bulk stuffs here

Then, map the column to the right data type as seen in the ColumnEnumHand property below.

var mappings = return new[]
{
    ...
    new NpgsqlBulkInsertMapItem(nameof(EnumTable.ColumnEnumInt), nameof(EnumTable.ColumnEnumInt), NpgsqlTypes.NpgsqlDbType.Integer),
    new NpgsqlBulkInsertMapItem(nameof(EnumTable.ColumnEnumHand), nameof(EnumTable.ColumnEnumHand), "hand")
}

// Pass to 'mappings' argument
var result = NpgsqlConnectionExtension.BinaryBulkInsert<EnumTable>(connection,
    tableName,
    entities: entities,
    mappings: Helper.GetEnumTableMappings());

Async Methods

Every synchronous operation has a corresponding Async overload.

BinaryBulkDelete

Deletes existing rows from the database in bulk. Returns the number of deleted rows.

BinaryBulkDelete via DataEntities

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

Or with qualifiers:

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

Or via table-name:

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

Or via table-name with qualifiers:

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

BinaryBulkDelete via DataTable

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

Or with qualifiers:

using (var connection = new NpgsqlConnection(ConnectionString))
{
	var table = GetCustomersAsDataTable();
	var deletedRows = connection.BinaryBulkDelete("Customer", table, qualifiers: Field.From("LastName", "DateOfBirth"));
}

BinaryBulkDelete via DbDataReader

using (var connection = new NpgsqlConnection(ConnectionString))
{
	using (var reader = connection.ExecuteReader("SELECT * FROM \"Customer\";"))
	{
		var deletedRows = connection.BinaryBulkDelete("Customer", reader);
	}
}

Or with qualifiers:

using (var connection = new NpgsqlConnection(ConnectionString))
{
	using (var reader = connection.ExecuteReader("SELECT * FROM \"Customer\";"))
	{
		var deletedRows = connection.BinaryBulkDelete("Customer", reader, qualifiers: Field.From("LastName", "DateOfBirth"));
	}
}

BinaryBulkDeleteByKey

Deletes existing rows from the database in bulk via a list of primary keys. Returns the number of deleted rows.

using (var connection = new NpgsqlConnection(ConnectionString))
{
	var primaryKeys = new [] { 1, 2, ..., 10045 };
	var deletedRows = connection.BinaryBulkDeleteByKey(primaryKeys);
}

BinaryBulkInsert

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

BinaryBulkInsert via DataEntities

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

Or via table-name:

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

BinaryBulkInsert via DataTable

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

BinaryBulkInsert via DbDataReader

using (var connection = new NpgsqlConnection(ConnectionString))
{
	using (var reader = connection.ExecuteReader("SELECT * FROM \"Customer\";"))
	{
		var insertedRows = connection.BinaryBulkInsert("Customer", reader);
	}
}

BinaryBulkMerge

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.

BinaryBulkMerge via DataEntities

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

Or with qualifiers:

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

Or via table-name:

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

Or via table-name with qualifiers:

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

BinaryBulkMerge via DataTable

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

Or with qualifiers:

using (var connection = new NpgsqlConnection(ConnectionString))
{
	var table = GetCustomersAsDataTable();
	var mergedRows = connection.BinaryBulkMerge("Customer", table, qualifiers: Field.From("LastName", "DateOfBirth"));
}

BinaryBulkMerge via DbDataReader

using (var connection = new NpgsqlConnection(ConnectionString))
{
	using (var reader = connection.ExecuteReader("SELECT * FROM \"Customer\";"))
	{
		var mergedRows = connection.BinaryBulkMerge("Customer", reader);
	}
}

Or with qualifiers:

using (var connection = new NpgsqlConnection(ConnectionString))
{
	using (var reader = connection.ExecuteReader("SELECT * FROM \"Customer\";"))
	{
		var mergedRows = connection.BinaryBulkMerge("Customer", reader, qualifiers: Field.From("LastName", "DateOfBirth"));
	}
}

BinaryBulkUpdate

Updates existing rows in the database in bulk. Returns the number of updated rows.

BinaryBulkUpdate via DataEntities

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

Or with qualifiers:

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

Or via table-name:

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

Or via table-name with qualifiers:

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

BinaryBulkUpdate via DataTable

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

Or with qualifiers:

using (var connection = new NpgsqlConnection(ConnectionString))
{
	var table = GetCustomersAsDataTable();
	var rows = connection.BinaryBulkUpdate("Customer", table, qualifiers: Field.From("LastName", "DateOfBirth"));
}

BinaryBulkUpdate via DbDataReader

using (var connection = new NpgsqlConnection(ConnectionString))
{
	using (var reader = connection.ExecuteReader("SELECT * FROM \"Customer\";"))
	{
		var rows = connection.BinaryBulkUpdate("Customer", reader);
	}
}

Or with qualifiers:

using (var connection = new NpgsqlConnection(ConnectionString))
{
	using (var reader = connection.ExecuteReader("SELECT * FROM \"Customer\";"))
	{
		var rows = connection.BinaryBulkUpdate("Customer", reader, qualifiers: Field.From("LastName", "DateOfBirth"));
	}
}
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.15.0 55 7/18/2026
1.15.0-telemetry 32 7/18/2026
1.14.0 2,202 6/28/2026
1.13.2-alpha1 1,582 2/26/2024
1.13.1 252,148 3/16/2023
1.13.0 2,723 11/2/2022
1.3.2-alpha1 225 2/26/2024
0.0.12 897 10/25/2022
0.0.11 856 10/6/2022
0.0.10 924 9/17/2022
0.0.9 107,202 2/18/2022
0.0.8 934 12/12/2021
0.0.7 869 11/9/2021
0.0.6 914 10/31/2021
0.0.5 864 10/27/2021
Loading failed