Net4x.DapperLibrary.Postgres 1.9.9

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

DapperLibrary.Postgres

PostgreSQL provider integration for DapperLibrary. This project supplies a Postgres-specific DapperContext implementation, a provider factory backed by Npgsql, and Postgres-specific database model and type mappings.

Purpose

Provide PostgreSQL engine-specific behavior while preserving the common DapperLibrary API. This includes:

  • PostgresDapperContext � a DapperContext configured for Npgsql with Use / UseOnce helpers.
  • NpgsqlProviderFactory � configures parameter handling and adapter events for the Npgsql provider.
  • PostgresDatabaseModel, PostgresDatabaseModelTypes and PostgresDatabaseEnumTypes � identifier delimiters, statement terminator, parameter naming and SQL type mappings for PostgreSQL.

Key types

  • PostgresDapperContext

    • Derives from DapperContext and initializes the context with NpgsqlProviderFactory and configuration from DapperConfigurationManager.
    • Static helpers Use, Use(IContextCreator), Use(string, string) and UseOnce integrate with DapperContextFactory and set common Postgres defaults (for example identity initializer and datetime formatting).
    • When used via Use helpers, contexts are configured with:
      • DatabaseModel.IdentityInitializer = "GENERATED ALWAYS AS IDENTITY"
      • DatabaseModel.FormatDatetimeAsString = dateTime => $"TIMESTAMP '{dateTime:yyyy-MM-dd HH:mm:ss.fff}'"
  • NpgsqlProviderFactory

    • Inherits from ProviderFactoryBase and uses NpgsqlFactory.Instance as the underlying provider.
    • Sets ParameterModel.ParameterPrefix = "@" and ParameterModel.AddIndex = true and installs a PrepareCommandParameters delegate.
    • Attaches RowUpdating / RowUpdated handlers to data adapters and exposes hooks to forward these events.
  • PostgresDatabaseModel and related types

    • Identifier delimiters: " (double-quote).
    • Statement terminator: ;.
    • Parameter prefix: @ and parameter base name: Par.
    • Type mappings reflect PostgreSQL types: uuid, jsonb, timestamptz, bytea, numeric, double precision, integer, bigint, boolean, etc.

Usage examples

Create and use a Postgres context directly:

using var context = new PostgresDapperContext();
// use context.Operations / context.Schema / context.SaveDataTable etc.

Register a context creator in bootstrap code:

PostgresDapperContext.Use();

// or bind an explicit connection string and provider name
PostgresDapperContext.UseOnce(connectionString, providerName);

When creating contexts via the static helpers, the database model will be pre-configured with Postgres-friendly defaults for identity columns and datetime literal formatting.

Multi-targeting & compatibility

  • The project is built to be compatible with .NET Standard (the current build artifacts are produced for .NET Standard targets in this repository). Consumer projects targeting modern .NET (5/6/8/10) or .NET Framework should reference the matching compiled asset from the package.
  • Conditional compilation and provider selection logic in the wider solution ensure the appropriate ADO.NET provider (Npgsql) is referenced for the target framework used by the consumer.

Synchronous vs asynchronous behavior

  • PostgreSQL (Npgsql) offers robust async I/O support. DapperLibrary exposes both synchronous and asynchronous variants for most operations (GetDataReaderAsync, GetDataTableAsync, SetDataAsync, QueryAsync<T>, etc.).
  • Prefer the Async-suffixed methods in server and I/O-bound applications to avoid blocking threads. The library uses async provider APIs where available and falls back to synchronous flows on frameworks/providers that lack Task-based ADO.NET async support.

Events and data adapter behavior

  • NpgsqlProviderFactory.CreateDataAdapter wires RowUpdated and RowUpdating events coming from NpgsqlDataAdapter and forwards them via the provider factory. This enables consumer code to hook into the DbDataAdapter row lifecycle when using SaveDataTable and related adapter-based persistence.

Notes and best practices

  • Use WithConnection overloads when executing operations against a different named connection for a single call to avoid race conditions around ConnectionStringToRead.
  • Prefer Use / UseOnce helpers to ensure consistent Postgres configuration across created contexts.
  • Rely on the schema helpers (IDapperContext.Schema) and cached metadata for efficient schema inspection.

For implementation details, consult the source files under DbContexts and the NpgsqlProviderFactory class.

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 is compatible. 
.NET Framework net461 was computed.  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 (1)

Showing the top 1 NuGet packages that depend on Net4x.DapperLibrary.Postgres:

Package Downloads
Net4x.DapperLibrary.Docker

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.9.9 25 12/22/2025
1.6.0.12 237 12/12/2025
1.6.0.11 206 12/12/2025
1.6.0.10 533 12/9/2025
1.6.0.9 180 12/4/2025
1.6.0.8 190 12/4/2025
1.6.0.7 246 11/30/2025
1.6.0.6 167 11/27/2025
1.6.0.5 219 11/22/2025
1.6.0.4 133 11/16/2025
1.6.0.3 168 11/15/2025
1.6.0.2 258 11/14/2025
1.6.0.1 229 11/10/2025
1.6.0 194 11/9/2025
1.5.0.3 176 11/5/2025
1.5.0.2 183 11/3/2025
1.5.0.1 184 11/3/2025
1.5.0 136 10/26/2025
1.4.1.6 162 10/24/2025
1.4.1.5 181 10/22/2025
1.4.1.4 197 10/22/2025