CoreEx.Database.Postgres
4.0.0-preview-1
dotnet add package CoreEx.Database.Postgres --version 4.0.0-preview-1
NuGet\Install-Package CoreEx.Database.Postgres -Version 4.0.0-preview-1
<PackageReference Include="CoreEx.Database.Postgres" Version="4.0.0-preview-1" />
<PackageVersion Include="CoreEx.Database.Postgres" Version="4.0.0-preview-1" />
<PackageReference Include="CoreEx.Database.Postgres" />
paket add CoreEx.Database.Postgres --version 4.0.0-preview-1
#r "nuget: CoreEx.Database.Postgres, 4.0.0-preview-1"
#:package CoreEx.Database.Postgres@4.0.0-preview-1
#addin nuget:?package=CoreEx.Database.Postgres&version=4.0.0-preview-1&prerelease
#tool nuget:?package=CoreEx.Database.Postgres&version=4.0.0-preview-1&prerelease
CoreEx.Database.Postgres
Provides the PostgreSQL (Npgsql) implementation of
IDatabase:PostgresDatabase,PostgresUnitOfWork, outbox relay, Postgres-specific parameter extensions, and OpenTelemetry metrics for outbox operations.
Overview
CoreEx.Database.Postgres is the PostgreSQL provider package built on top of CoreEx.Database. It supplies concrete implementations of every abstract type in that package — PostgresDatabase, PostgresCommand, PostgresDatabaseArgs, PostgresDatabaseColumns — and adds PostgreSQL-specific capabilities: structured error-code mapping from PostgreSQL SqlState strings to CoreEx semantic exceptions, and PostgresUnitOfWork for transactional outbox support.
The error-code mapping convention mirrors the SQL Server convention: stored procedures and functions raise well-known SQLSTATE codes (56001–56010) to signal domain exceptions without any application-layer switch statements. Unique-violation errors (23505 by default) are automatically converted to DuplicateException.
The outbox sub-namespace provides ready-to-use PostgresOutboxPublisher, PostgresOutboxRelay, and PostgresOutboxRelayHostedService with .NET Meter-backed counters and histograms for enqueue throughput and relay lag.
Key capabilities
- 🗃️ PostgresDatabase: Concrete
IDatabaseforNpgsqlConnection(constructed fromNpgsqlDataSource); maps PostgreSQLSqlStatestrings to CoreEx semantic exceptions; configurableDuplicateErrorNumbers;RowVersionencoded viaEncodedStringToUInt32Converter. - 🔢 Error-code convention:
SQLSTATEvalues 56001–56007 and 56010 map toValidationException,BusinessException,AuthorizationException,ConcurrencyException,NotFoundException,ConflictException,DuplicateException, andDataConsistencyExceptionrespectively — identical to the SQL Server convention. - 🔁 PostgresUnitOfWork:
IDatabaseUnitOfWorkimplementation wrappingTransactionAsyncwithPostgresUnitOfWorkInvoker; optionally accepts anIEventPublisheroutbox for transactional event enqueuing. - 📤 Outbox relay:
PostgresOutboxPublisher(writes to outbox table),PostgresOutboxRelay(polls and publishes), andPostgresOutboxRelayHostedService(timer-driven hosted service) — all PostgreSQL-specific subclasses of the baseCoreEx.Database.Outboxtypes. - 📊 Outbox metrics:
PostgresMetricsexposes .NETMeterinstruments:postgres.outbox.enqueue(counter),postgres.outbox.relay.batch.size(counter),postgres.outbox.batch.oldest_lagandpostgres.outbox.batch.newest_lag(histograms in ms). - 📡 OpenTelemetry:
CoreExPostgresExtensions.AddCoreExPostgresOpenTelemetrywiresPostgresInvokeractivity sources and the outbox meter into the OTEL tracer and meter providers. - ⚙️ DI registration:
AddPostgresDatabase<TDatabase>(services, configure?)registersPostgresDatabaseas a scoped service;AddPostgresUnitOfWork(services, configure?)registersPostgresUnitOfWork.
Key types
| Type | Description |
|---|---|
PostgresDatabase |
Concrete IDatabase for NpgsqlConnection; SqlState string to exception mapping; RowVersion → EncodedStringToUInt32Converter; accepts NpgsqlDataSource for connection-pool management. |
PostgresUnitOfWork |
IDatabaseUnitOfWork implementation; wraps TransactionAsync with PostgresUnitOfWorkInvoker; optional transactional outbox via IEventPublisher Outbox. |
PostgresCommand |
DatabaseCommand subclass for NpgsqlCommand; adds Postgres-specific parameter handling. |
PostgresDatabaseArgs |
DatabaseArgs subclass with PostgreSQL-specific defaults. |
PostgresDatabaseColumns |
DatabaseColumns subclass with PostgreSQL-specific convention column name defaults (e.g. snake_case names). |
PostgresMetrics |
Static .NET Meter with counters and histograms for outbox enqueue throughput and relay lag. |
PostgresOutboxPublisher |
DatabaseOutboxPublisherBase for PostgreSQL; inserts event rows into the outbox table via a configurable function/procedure. |
PostgresOutboxRelay |
DatabaseOutboxRelayBase<PostgresDatabase, PostgresOutboxRelay> with PostgreSQL-specific dequeue/complete SQL; records outbox metrics per batch. |
PostgresOutboxRelayHostedService |
DatabaseOutboxRelayHostedServiceBase<PostgresOutboxRelay> timer-driven hosted service for the PostgreSQL outbox relay. |
PostgresExtensions |
IDatabase / DatabaseCommand extensions specific to PostgreSQL: Param helpers for NpgsqlDbType-typed parameters. |
PostgresInvoker |
DatabaseInvoker subclass for PostgreSQL; the Default singleton used by PostgresDatabase. |
PostgresUnitOfWorkInvoker |
InvokerBase<PostgresUnitOfWork> wrapping TransactionAsync with OpenTelemetry spans and begin/commit/rollback log entries. |
Related Namespaces
CoreEx.Database- Abstract base types (Database<TConn>,DatabaseCommand,DatabaseRecord,DatabaseOutboxRelayBase,IDatabaseMapper) that all PostgreSQL types extend.CoreEx.Data-IUnitOfWorkandIDatabaseUnitOfWorkinterfaces implemented byPostgresUnitOfWork.CoreEx.Events-IEventPublisheris the relay's publication target;PostgresOutboxPublisherimplementsIEventPublisher.CoreEx.Invokers-PostgresInvokerandPostgresUnitOfWorkInvokerextendInvokerBasefor OpenTelemetry tracing.
Additional Resources
- Npgsql - The PostgreSQL ADO.NET driver this package uses.
- PostgreSQL Error Codes - Reference for
SqlStatevalues including the CoreEx convention codes.
AI Usage Guide
An AGENTS.md file is included with this package. AI coding assistants (GitHub Copilot, Claude, Cursor, etc.) that support workspace-injected package documentation will automatically surface concise usage guidance, code examples, and Do Not rules for this package without requiring a local CoreEx checkout.
| Product | Versions 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. |
-
net10.0
- Aspire.Azure.Npgsql (>= 13.1.1)
- CoreEx (>= 4.0.0-preview-1)
- CoreEx.Data (>= 4.0.0-preview-1)
- CoreEx.Database (>= 4.0.0-preview-1)
-
net8.0
- Aspire.Azure.Npgsql (>= 13.1.1)
- CoreEx (>= 4.0.0-preview-1)
- CoreEx.Data (>= 4.0.0-preview-1)
- CoreEx.Database (>= 4.0.0-preview-1)
-
net9.0
- Aspire.Azure.Npgsql (>= 13.1.1)
- CoreEx (>= 4.0.0-preview-1)
- CoreEx.Data (>= 4.0.0-preview-1)
- CoreEx.Database (>= 4.0.0-preview-1)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on CoreEx.Database.Postgres:
| Package | Downloads |
|---|---|
|
CoreEx.UnitTesting
Core .NET extensions and abstractions for the testing of backend services. |
|
|
Beef.Database.Postgres
Business Entity Execution Framework (Beef) PostgreSQL Database tool. |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on CoreEx.Database.Postgres:
| Repository | Stars |
|---|---|
|
Avanade/Beef
The Business Entity Execution Framework (Beef) framework, and the underlying code generation, has been primarily created to support the industrialization of API development.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.0-preview-1 | 43 | 6/20/2026 |
| 3.31.0 | 963 | 2/1/2025 |
| 3.30.2 | 214 | 12/11/2024 |
| 3.30.1 | 174 | 12/9/2024 |
| 3.30.0 | 847 | 11/21/2024 |
| 3.29.0 | 344 | 11/19/2024 |
| 3.28.0 | 225 | 11/9/2024 |
| 3.27.3 | 235 | 10/23/2024 |
| 3.27.2 | 206 | 10/17/2024 |
| 3.27.1 | 259 | 10/15/2024 |
| 3.27.0 | 338 | 10/11/2024 |
| 3.26.0 | 218 | 10/3/2024 |
| 3.25.6 | 367 | 10/2/2024 |
| 3.25.5 | 258 | 9/25/2024 |
| 3.25.4 | 238 | 9/24/2024 |
| 3.25.3 | 226 | 9/18/2024 |
| 3.25.2 | 242 | 9/17/2024 |
| 3.25.1 | 285 | 9/16/2024 |
| 3.25.0 | 214 | 9/10/2024 |
| 3.24.1 | 296 | 8/7/2024 |