SyntaxCircus.EntityFrameworkCore.Postgres
0.1.3
dotnet add package SyntaxCircus.EntityFrameworkCore.Postgres --version 0.1.3
NuGet\Install-Package SyntaxCircus.EntityFrameworkCore.Postgres -Version 0.1.3
<PackageReference Include="SyntaxCircus.EntityFrameworkCore.Postgres" Version="0.1.3" />
<PackageVersion Include="SyntaxCircus.EntityFrameworkCore.Postgres" Version="0.1.3" />
<PackageReference Include="SyntaxCircus.EntityFrameworkCore.Postgres" />
paket add SyntaxCircus.EntityFrameworkCore.Postgres --version 0.1.3
#r "nuget: SyntaxCircus.EntityFrameworkCore.Postgres, 0.1.3"
#:package SyntaxCircus.EntityFrameworkCore.Postgres@0.1.3
#addin nuget:?package=SyntaxCircus.EntityFrameworkCore.Postgres&version=0.1.3
#tool nuget:?package=SyntaxCircus.EntityFrameworkCore.Postgres&version=0.1.3
SyntaxCircus.EntityFrameworkCore.Postgres
An auditable-entity base with a TimeProvider-driven SaveChanges interceptor, a Postgres advisory-lock-guarded migrate-on-startup helper, snake_case entity/column naming, and a snake_case migrations-history repository — for products on EF Core + Npgsql.
No support guaranteed. Published as-is and maintained on a best-effort basis. Issues and PRs are welcome, but there's no SLA — fork it or vendor what you need if that's not enough.
Auditable entities
public sealed class Widget : AuditableEntity
{
public string Name { get; set; } = string.Empty;
}
optionsBuilder.UseNpgsql(connectionString);
optionsBuilder.AddTrackableEntityInterceptor(); // stamps CreatedAt/UpdatedAt on save
AuditableEntity gives you Id, CreatedAt, UpdatedAt. If you already have a base entity, just implement ITrackableEntity (CreatedAt/UpdatedAt) instead — the interceptor works off the interface, not the base class. AddTrackableEntityInterceptor(timeProvider) takes an optional TimeProvider for testability; defaults to TimeProvider.System.
Migrate on startup, safely
await using var scope = app.Services.CreateAsyncScope();
var context = scope.ServiceProvider.GetRequiredService<MyDbContext>();
await context.MigrateWithAdvisoryLockAsync(lockKey: 823_471); // any consistent int64 for this DbContext
Takes a Postgres advisory lock before calling Database.MigrateAsync(), so multiple instances of the same service starting up concurrently don't race to apply migrations. Falls back to a plain, lock-free migrate for non-Postgres providers.
Snake_case entity and column naming
This package depends on EFCore.NamingConventions and wraps its UseSnakeCaseNamingConvention():
optionsBuilder.UseNpgsql(connectionString)
.UseSyntaxCircusSnakeCaseNamingConvention(); // entity and column names become snake_case, e.g. CreatedAt -> created_at
Use UseSyntaxCircusSnakeCaseNamingConvention(), not the raw UseSnakeCaseNamingConvention() from EFCore.NamingConventions directly - a naming-convention plugin applies to every model built from the context's convention pipeline, including the internal model EF Core uses for its own __EFMigrationsHistory migrations-history table. Calling the raw method alone silently renames that framework-owned table's columns as an unadvertised side effect (confirmed: it isn't a consumer-owned entity, so this is unintended - see docs/enhancements/2026-08-17-missing-snake-case-naming-convention.md). UseSyntaxCircusSnakeCaseNamingConvention() snake-cases your own entities the same way, while automatically keeping the migrations-history table in its EF Core framework-default naming (__EFMigrationsHistory / MigrationId / ProductVersion) unless you opt into renaming it too (below).
EFCore.NamingConventions also ships camelCase, lower_case, and other convention variants — call its own UseSnakeCaseNamingConvention()/etc. directly if you want one of those without this package's migrations-history protection.
Snake_case migrations history table
If you've opted into UseSyntaxCircusSnakeCaseNamingConvention() above and do want the migrations-history table itself (__ef_migrations_history, migration_id, product_version) renamed to match — note this requires a one-time manual column rename on any database that already has migrations applied under the old naming, since EF has to read that table to know which migrations are applied before it can run one that would rename it:
optionsBuilder.UseNpgsql(connectionString)
.UseSyntaxCircusSnakeCaseNamingConvention()
.ReplaceService<IHistoryRepository, SnakeCaseHistoryRepository>(); // registered after, so it wins
Contributing
Issues and pull requests are welcome:
- Keep changes focused, with a clear description of the behavior change.
- Match the existing code style (see
.editorconfig). - Call out any breaking changes to the public API in your PR description.
License
MIT — see LICENSE.txt.
| 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
- EFCore.NamingConventions (>= 10.0.1)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 10.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.