Pandatech.SharedKernel.Postgres
2.1.0
dotnet add package Pandatech.SharedKernel.Postgres --version 2.1.0
NuGet\Install-Package Pandatech.SharedKernel.Postgres -Version 2.1.0
<PackageReference Include="Pandatech.SharedKernel.Postgres" Version="2.1.0" />
<PackageVersion Include="Pandatech.SharedKernel.Postgres" Version="2.1.0" />
<PackageReference Include="Pandatech.SharedKernel.Postgres" />
paket add Pandatech.SharedKernel.Postgres --version 2.1.0
#r "nuget: Pandatech.SharedKernel.Postgres, 2.1.0"
#:package Pandatech.SharedKernel.Postgres@2.1.0
#addin nuget:?package=Pandatech.SharedKernel.Postgres&version=2.1.0
#tool nuget:?package=Pandatech.SharedKernel.Postgres&version=2.1.0
Pandatech.SharedKernel.Postgres
PostgreSQL integration helpers for ASP.NET Core 10. Wraps Npgsql, Entity Framework Core, health checks, exception mapping, query locks, snake_case naming, and audit trail wiring into a small set of extension methods so every service starts from the same consistent baseline.
Requires .NET 10.0. Uses C# 14 extension members and cannot be downgraded.
Table of Contents
- Installation
- What is included
- Registering a DbContext
- Migrations
- Model configuration helpers
- Health checks
Installation
dotnet add package Pandatech.SharedKernel.Postgres
What is included
Every AddPostgresContext* overload automatically applies the following to your DbContext:
| Feature | Source package |
|---|---|
| Npgsql provider | Npgsql.EntityFrameworkCore.PostgreSQL |
| Snake_case naming convention | EFCore.NamingConventions |
Query locks (FOR UPDATE etc.) |
Pandatech.EFCore.PostgresExtensions |
| Friendly exception mapping | EntityFrameworkCore.Exceptions.PostgreSQL |
AuditBase property validation |
Pandatech.EFCore.AuditBase |
| Audit trail interceptors (opt-in) | Pandatech.EFCore.Audit |
| Postgres health check | AspNetCore.HealthChecks.NpgSql |
| Bulk extensions | EFCore.BulkExtensions.PostgreSql |
| Gridify query extensions | Pandatech.GridifyExtensions |
Registering a DbContext
All overloads are on WebApplicationBuilder and return WebApplicationBuilder for chaining. Every variant
automatically registers a Postgres health check named postgres_{DatabaseName}.
Basic registration (no pooling, no audit trail)
// Minimal — connection string only
builder.AddPostgresContext<AppDbContext>(connectionString);
// With migrations assembly by name
builder.AddPostgresContext<AppDbContext>(connectionString, "MyApp.Migrations");
// With migrations assembly by Assembly reference
builder.AddPostgresContext<AppDbContext>(connectionString, typeof(Program).Assembly);
// With migrations assembly by marker type
builder.AddPostgresContext<AppDbContext, Program>(connectionString);
// Full control via NpgsqlDbContextOptionsBuilder callback
builder.AddPostgresContext<AppDbContext>(connectionString, npgsql =>
{
npgsql.MigrationsAssembly("MyApp.Migrations");
npgsql.CommandTimeout(60);
});
With connection pooling
Same set of overloads, prefixed with Pool:
builder.AddPostgresContextPool<AppDbContext>(connectionString);
builder.AddPostgresContextPool<AppDbContext>(connectionString, "MyApp.Migrations");
builder.AddPostgresContextPool<AppDbContext, Program>(connectionString);
builder.AddPostgresContextPool<AppDbContext>(connectionString, npgsql => { ... });
Use pooling for high-throughput services. Note that DbContext pooling requires that your context has no scoped
dependencies injected via the constructor; use service provider overloads ((sp, options) => ...) for those cases.
With audit trail (no pooling)
Registers the Pandatech.EFCore.Audit interceptors alongside the standard options:
builder.AddPostgresContextWithAuditTrail<AppDbContext>(connectionString);
builder.AddPostgresContextWithAuditTrail<AppDbContext>(connectionString, "MyApp.Migrations");
builder.AddPostgresContextWithAuditTrail<AppDbContext, Program>(connectionString);
builder.AddPostgresContextWithAuditTrail<AppDbContext>(connectionString, npgsql => { ... });
With pooling and audit trail
builder.AddPostgresContextPoolWithAuditTrail<AppDbContext>(connectionString);
builder.AddPostgresContextPoolWithAuditTrail<AppDbContext>(connectionString, "MyApp.Migrations");
builder.AddPostgresContextPoolWithAuditTrail<AppDbContext, Program>(connectionString);
builder.AddPostgresContextPoolWithAuditTrail<AppDbContext>(connectionString, npgsql => { ... });
Migrations
Apply pending migrations at startup:
// Synchronous
app.MigrateDatabase<AppDbContext>();
// Asynchronous
await app.MigrateDatabaseAsync<AppDbContext>(ct);
Both create a scoped service provider, resolve the context, and call Database.Migrate / Database.MigrateAsync.
Place these calls after app.Build() and before app.Run().
Model configuration helpers
Add to ConfigureConventions and OnModelCreating in your DbContext:
protected override void ConfigureConventions(ModelConfigurationBuilder builder)
{
// Map all decimal properties to NUMERIC(40, 20) — prevents precision loss
builder.ConfigureDecimalType();
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Set all foreign key delete behavior to Restrict (no accidental cascades)
modelBuilder.RestrictFkDeleteBehaviorByDefault();
}
ConfigureDecimalType sets precision (40, 20) globally. Override individual properties via [Precision] or fluent
API if you need a narrower type for a specific column.
RestrictFkDeleteBehaviorByDefault iterates all foreign keys at model build time and sets DeleteBehavior.Restrict.
Override individual relationships fluently after this call if cascade delete is intentionally needed.
Health checks
The health check is registered automatically by every AddPostgresContext* overload. It uses
AspNetCore.HealthChecks.NpgSql with a 5-second timeout and is named postgres_{DatabaseName} where the database
name is parsed from the connection string.
To expose the health check endpoint, use MapHealthCheckEndpoints() from Pandatech.SharedKernel:
app.MapHealthCheckEndpoints(); // /above-board/health
Or register your own endpoint:
app.MapHealthChecks("/health");
If the database name cannot be parsed from the connection string, registration throws ArgumentException at startup
rather than silently registering a misnamed check.
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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
- AspNetCore.HealthChecks.NpgSql (>= 9.0.0)
- EFCore.BulkExtensions.PostgreSql (>= 10.0.1)
- EFCore.NamingConventions (>= 10.0.1)
- EntityFrameworkCore.Exceptions.PostgreSQL (>= 8.1.3)
- Pandatech.EFCore.Audit (>= 3.0.0)
- Pandatech.EFCore.AuditBase (>= 5.0.0)
- Pandatech.EFCore.PostgresExtensions (>= 7.0.0)
- Pandatech.GridifyExtensions (>= 4.0.0)
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 |
|---|---|---|
| 2.1.0 | 85 | 2/28/2026 |
| 2.0.2 | 121 | 1/27/2026 |
| 2.0.1 | 63 | 12/29/2025 |
| 2.0.0 | 60 | 12/29/2025 |
| 1.0.42 | 175 | 12/26/2025 |
| 1.0.41 | 167 | 12/14/2025 |
| 1.0.40 | 163 | 12/14/2025 |
| 1.0.39 | 210 | 12/5/2025 |
| 1.0.38 | 225 | 10/13/2025 |
| 1.0.37 | 200 | 10/13/2025 |
| 1.0.36 | 181 | 9/26/2025 |
| 1.0.35 | 270 | 9/22/2025 |
| 1.0.34 | 209 | 9/11/2025 |
| 1.0.33 | 210 | 9/8/2025 |
| 1.0.32 | 146 | 8/15/2025 |
| 1.0.31 | 167 | 8/15/2025 |
| 1.0.30 | 179 | 8/15/2025 |
| 1.0.29 | 240 | 6/1/2025 |
| 1.0.28 | 227 | 5/7/2025 |
| 1.0.27 | 205 | 4/11/2025 |
Removed unused OpenAPI reference; FrameworkReference for ASP.NET Core types.