![]() |
VOOZH | about |
dotnet add package Dosaic.Plugins.Persistence.EfCore.NpgSql --version 1.2.34
NuGet\Install-Package Dosaic.Plugins.Persistence.EfCore.NpgSql -Version 1.2.34
<PackageReference Include="Dosaic.Plugins.Persistence.EfCore.NpgSql" Version="1.2.34" />
<PackageVersion Include="Dosaic.Plugins.Persistence.EfCore.NpgSql" Version="1.2.34" />Directory.Packages.props
<PackageReference Include="Dosaic.Plugins.Persistence.EfCore.NpgSql" />Project file
paket add Dosaic.Plugins.Persistence.EfCore.NpgSql --version 1.2.34
#r "nuget: Dosaic.Plugins.Persistence.EfCore.NpgSql, 1.2.34"
#:package Dosaic.Plugins.Persistence.EfCore.NpgSql@1.2.34
#addin nuget:?package=Dosaic.Plugins.Persistence.EfCore.NpgSql&version=1.2.34Install as a Cake Addin
#tool nuget:?package=Dosaic.Plugins.Persistence.EfCore.NpgSql&version=1.2.34Install as a Cake Tool
Dosaic.Plugins.Persistence.EfCore.NpgSql is a Dosaic plugin that integrates PostgreSQL into the EF Core persistence layer via the Npgsql provider. It provides connection and pool configuration, automatic PostgreSQL enum mapping via [DbEnumAttribute], lambda injection support, and a hosted background migration service.
dotnet add package Dosaic.Plugins.Persistence.EfCore.NpgSql
Or add directly to your .csproj:
<PackageReference Include="Dosaic.Plugins.Persistence.EfCore.NpgSql" Version="" />
The plugin binds its configuration from the npgsql section via the [Configuration("npgsql")] attribute on EfCoreNpgSqlConfiguration.
npgsql:
host: "localhost"
port: 5432
database: "mydb"
username: "postgres"
password: "postgres"
connectionLifetime: 60 # seconds; 0 = indefinite (default: 60)
keepAlive: 15 # seconds; 0 = disabled (default: 15)
maxPoolSize: 100 # (default: 100)
configureLoggingCacheTimeInSeconds: 300 # (default: 300)
splitQuery: false # use SplitQuery behaviour (default: false)
includeErrorDetail: false # include PG error details — may expose sensitive data
enableDetailedErrors: false # EF Core detailed errors — may expose sensitive data
enableSensitiveDataLogging: false # log parameter values — may expose sensitive data
// Automatically resolved by Dosaic via [Configuration("npgsql")]
[Configuration("npgsql")]
public class EfCoreNpgSqlConfiguration
{
public string Host { get; set; }
public int Port { get; set; } = 5432;
public string Database { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public int ConnectionLifetime { get; set; } = 60;
public int KeepAlive { get; set; } = 15;
public int MaxPoolSize { get; set; } = 100;
public int ConfigureLoggingCacheTimeInSeconds { get; set; } = 300;
public bool IncludeErrorDetail { get; set; }
public bool EnableDetailedErrors { get; set; }
public bool EnableSensitiveDataLogging { get; set; }
public bool SplitQuery { get; set; }
}
EfCoreNpgSqlConfiguration is injected automatically by the Dosaic TypeImplementationResolver.
Use ConfigureNpgSqlContext<TDbContext> to wire up the Npgsql provider on your DbContextOptionsBuilder.
using Dosaic.Hosting.Abstractions.Plugins;
using Dosaic.Plugins.Persistence.EfCore.Abstractions;
using Dosaic.Plugins.Persistence.EfCore.NpgSql;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
public class MyPlugin(EfCoreNpgSqlConfiguration npgsqlConfig)
: IPluginServiceConfiguration, IPluginHealthChecksConfiguration
{
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<MyDbContext>(
(provider, options) => options.ConfigureNpgSqlContext<MyDbContext>(provider, npgsqlConfig));
// Optional: run EF migrations in the background on startup
services.AddNpgsqlDbMigratorService<MyDbContext>();
}
public void ConfigureHealthChecks(IHealthChecksBuilder healthChecks)
{
healthChecks.AddEfCoreContext<MyDbContext>();
}
}
using Dosaic.Plugins.Persistence.EfCore.Abstractions.Database;
using Microsoft.EntityFrameworkCore;
public class MyDbContext(DbContextOptions<MyDbContext> options) : EfCoreDbContext(options)
{
public DbSet<Order> Orders { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Order>(e =>
{
e.HasKey(x => x.Id);
e.Property(x => x.Id).IsRequired();
});
// register any [DbEnum]-attributed enums for this context
modelBuilder.MapDbEnums<MyDbContext>();
base.OnModelCreating(modelBuilder);
}
}
Decorate your C# enums with [DbEnum] to have them automatically mapped to PostgreSQL enum types.
PostgresEnumExtensions scans all enums bearing this attribute in the assembly of your TDbContext
(and in the EF Core Abstractions assembly) and registers them with the Npgsql provider.
using Dosaic.Plugins.Persistence.EfCore.Abstractions.Database;
[DbEnum("order_status", "public")]
public enum OrderStatus
{
Pending,
Processing,
Shipped,
Delivered,
Cancelled,
}
The enum values are translated to snake_case names (e.g. Processing → processing) automatically via NpgsqlSnakeCaseNameTranslator.
Pass an optional Action<NpgSqlConfiguration> to ConfigureNpgSqlContext to further customise the provider:
services.AddDbContext<MyDbContext>((provider, options) =>
options.ConfigureNpgSqlContext<MyDbContext>(provider, npgsqlConfig, c =>
{
// Provide a pre-built NpgsqlDataSource (e.g. for password rotation)
c.WithDataSource(dataSourceBuilder =>
{
dataSourceBuilder.UsePeriodicPasswordProvider(/* ... */);
});
// Fine-tune the Npgsql EF builder
c.WithNpgSql(npgsql =>
{
npgsql.CommandTimeout(60);
});
// Override EF Core warning behaviour
c.WithWarnings(w =>
{
w.Log((CoreEventId.RowLimitingOperationWithoutOrderByWarning, LogLevel.Debug));
});
// Use a pre-compiled EF Core model (AOT / startup performance)
c.WithModel(MyDbContextModel.Instance);
}));
NpgsqlDbMigratorService<TDbContext> is a hosted BackgroundService that:
Register it with:
services.AddNpgsqlDbMigratorService<MyDbContext>();
Npgsql.EntityFrameworkCore.PostgreSQL with a fully configured NpgsqlDataSourceMaxPoolSize, ConnectionLifetime, KeepAlive, and ArrayNullabilityMode=PerInstance[DbEnumAttribute] marks C# enums; MapDbEnums<TDbContext> registers them on both the data source builder and the model builder with snake_case translationSplitQuery to switch between SingleQuery and SplitQuery behaviour globallyNeinLinq lambda injection is enabled automatically via WithLambdaInjection()NpgsqlDbMigratorService<TDbContext> applies pending migrations on startup and reloads Npgsql types afterwardAddEfCoreContext<TDbContext> (from Dosaic.Plugins.Persistence.EfCore.Abstractions) to expose a readiness health check for the database contextOpenTelemetry.Instrumentation.EntityFrameworkCore is included automatically| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.34 | 60 | 6/10/2026 |
| 1.2.33 | 66 | 6/2/2026 |
| 1.2.31 | 68 | 5/28/2026 |
| 1.2.30 | 75 | 5/7/2026 |
| 1.2.29 | 76 | 5/5/2026 |
| 1.2.28 | 83 | 4/30/2026 |
| 1.2.27 | 63 | 4/29/2026 |
| 1.2.26 | 69 | 4/29/2026 |
| 1.2.25 | 75 | 4/27/2026 |
| 1.2.24 | 70 | 4/21/2026 |
| 1.2.23 | 72 | 4/14/2026 |
| 1.2.22 | 70 | 4/10/2026 |
| 1.2.21 | 64 | 4/10/2026 |
| 1.2.20 | 67 | 4/10/2026 |
| 1.2.19 | 68 | 4/9/2026 |
| 1.2.18 | 76 | 4/2/2026 |
| 1.2.17 | 67 | 4/1/2026 |
| 1.2.16 | 62 | 4/1/2026 |
| 1.2.15 | 69 | 3/31/2026 |
| 1.2.14 | 68 | 3/30/2026 |