Net4x.DapperLibrary.MergeUtility 1.9.9.6

dotnet add package Net4x.DapperLibrary.MergeUtility --version 1.9.9.6
                    
NuGet\Install-Package Net4x.DapperLibrary.MergeUtility -Version 1.9.9.6
                    
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="Net4x.DapperLibrary.MergeUtility" Version="1.9.9.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Net4x.DapperLibrary.MergeUtility" Version="1.9.9.6" />
                    
Directory.Packages.props
<PackageReference Include="Net4x.DapperLibrary.MergeUtility" />
                    
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 Net4x.DapperLibrary.MergeUtility --version 1.9.9.6
                    
#r "nuget: Net4x.DapperLibrary.MergeUtility, 1.9.9.6"
                    
#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 Net4x.DapperLibrary.MergeUtility@1.9.9.6
                    
#: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=Net4x.DapperLibrary.MergeUtility&version=1.9.9.6
                    
Install as a Cake Addin
#tool nuget:?package=Net4x.DapperLibrary.MergeUtility&version=1.9.9.6
                    
Install as a Cake Tool

DapperLibrary.MergeUtility

Utilities to merge in-memory data (primarily DataTable) into a relational database table via the DapperLibrary IDapperContext abstractions. The library provides a configurable merge engine that generates and executes insert/update/delete statements according to the provided source data and database metadata.

Overview

  • Purpose: synchronize rows from an in-memory source (e.g. DataTable, DbDataReader or key/value pairs) into a target database table while handling inserts, updates and optional deletes of non-existing rows.
  • The engine is designed to be provider-agnostic: it maps CLR types to database types, prepares parameters, formats SQL and executes batched operations using the host IDapperContext.

Main components

  • IMergeHelper � simple public interface exposing Merge() and MergeDataTable(params string[]? primaryKeys).

  • MergeHelper (extensions) � extension methods on IDapperContext that:

    • MergeDataTable(DataTable? dataTable, params string[] primaryKeys) � convenience wrapper to run a merge for a DataTable.
    • MergeDataTable(DataTable? dataTable, bool deleteNonExisting, params string[] primaryKeys) � same but optionally delete rows in the DB that are not present in the source.
    • Factory methods to create IMergeHelper instances from DataTable, DbDataReader or arrays of key/value pairs.
  • MergeHelperInternal and supporting internals � the core implementation (split across files) that:

    • Computes table metadata (TableMetaData) and column mappings.
    • Builds parameterized SQL statements for INSERT, UPDATE and DELETE operations using SqlFormatter and RowHelperBase/RowInsertHelper/RowUpdateHelper/RowDeleteHelper.
    • Manages value extraction/wrapping for DataTable and DbDataReader sources via data wrappers.
    • Provides hooks for dumping generated SQL (DumperInternal) and for processing rows before save (ProcessRowBeforeSaveEventArgs).
  • Mapping and helpers

    • Type mapping (DbTypeMapper, ToDbTypeHelper, DataBaseConstants) ensures parameters use appropriate DbType values for the provider.
    • ParameterReplacerHelper and ParameterReplaceExtension assist with named/positional parameter transformation when generating provider-specific SQL.
    • MergeHelperCreator is used to create the internal helper instances (internal factory/DI style).

Usage examples

Merge a DataTable into the database:

// 'context' is an IDapperContext instance
int affected = context.MergeDataTable(myDataTable, "Id");

// With delete of non-existing rows
int affected2 = context.MergeDataTable(myDataTable, true, "Id");

Create and use a merge helper directly:

var helper = context.CreateMergeHelper(myDataTable);
helper.Merge();

Create a helper from a DbDataReader or from in-memory key/value pairs:

var readerHelper = context.CreateMergeHelper(myDbDataReader, "MyTable");
var kvpHelper = context.CreateMergeHelper(keyValuePairsArray, "MyTable");

Behavior & customization

  • The extension MergeDataTable sets the DataTable.PrimaryKey based on the provided primaryKeys and ensures the target table exists by calling CreateDataTableIfNotExists on the IDapperContext prior to merging.
  • MergeHelperInternal exposes options and events (internal) to tweak behaviors such as SQL dumping, row pre-processing and delete handling.
  • The engine tries to be efficient and safe by using parameterized statements and provider-aware DbType settings.

Dependencies and compatibility

  • Depends on DapperLibrary.DbContexts for IDapperContext integration and database operations.
  • Relies on internal mapping and helper classes in the DapperLibrary.MergeUtility project; no external database-specific code is required by callers.
  • The project contains conditional compilation to support older .NET Framework targets and modern .NET runtimes. Use the build appropriate assemblies for your runtime.

Notes

  • The merge implementation is intended for typical OLTP-sized datasets. For very large datasets consider batching or ETL-style approaches.
  • SQL generation and parameter handling are provider-aware but edge-case SQL dialect differences may require inspection of the dumped statements (DumperInternal) when diagnosing issues.

License / Contributing

See repository root for license and contribution guidelines.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net35 is compatible.  net40 is compatible.  net403 was computed.  net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
1.9.9.6 36 1/6/2026
1.9.9.5 37 1/6/2026
1.9.9.4 33 1/6/2026
1.9.9.3 85 1/5/2026
1.9.9.2 105 12/30/2025
1.9.9.1 114 12/30/2025
1.9.9 171 12/22/2025
1.6.0.12 128 12/12/2025
1.6.0.11 121 12/12/2025
1.6.0.10 455 12/9/2025
1.6.0.9 204 12/4/2025
1.6.0.8 198 12/4/2025
1.6.0.7 270 11/30/2025
1.6.0.6 204 11/27/2025
1.6.0.5 233 11/22/2025
1.6.0.4 170 11/16/2025
1.6.0.3 183 11/15/2025
1.6.0.2 279 11/14/2025
1.6.0.1 253 11/10/2025
1.6.0 211 11/9/2025
1.5.0.3 198 11/5/2025
1.5.0.2 203 11/3/2025
1.5.0.1 201 11/3/2025
1.5.0 167 10/26/2025
1.4.1.6 202 10/24/2025
1.4.1.5 191 10/22/2025
1.4.1.4 199 10/22/2025
1.4.1.2 201 5/30/2025
1.4.1.1 195 4/30/2025
1.4.1 209 4/30/2025
1.4.0 238 3/31/2025
1.1.0 235 8/26/2023