SyntaxCircus.EntityFrameworkCore.Postgres
0.1.2
See the version list below for details.
dotnet add package SyntaxCircus.EntityFrameworkCore.Postgres --version 0.1.2
NuGet\Install-Package SyntaxCircus.EntityFrameworkCore.Postgres -Version 0.1.2
<PackageReference Include="SyntaxCircus.EntityFrameworkCore.Postgres" Version="0.1.2" />
<PackageVersion Include="SyntaxCircus.EntityFrameworkCore.Postgres" Version="0.1.2" />
<PackageReference Include="SyntaxCircus.EntityFrameworkCore.Postgres" />
paket add SyntaxCircus.EntityFrameworkCore.Postgres --version 0.1.2
#r "nuget: SyntaxCircus.EntityFrameworkCore.Postgres, 0.1.2"
#:package SyntaxCircus.EntityFrameworkCore.Postgres@0.1.2
#addin nuget:?package=SyntaxCircus.EntityFrameworkCore.Postgres&version=0.1.2
#tool nuget:?package=SyntaxCircus.EntityFrameworkCore.Postgres&version=0.1.2
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, so its UseSnakeCaseNamingConvention() is available with no separate install:
optionsBuilder.UseNpgsql(connectionString)
.UseSnakeCaseNamingConvention(); // entity and column names become snake_case, e.g. CreatedAt -> created_at
EFCore.NamingConventions also ships camelCase, lower_case, and other convention variants — see its own docs for the full list.
Snake_case migrations history table
If you've also opted into UseSnakeCaseNamingConvention() above and want the migrations-history table itself (__ef_migrations_history, migration_id, product_version) renamed to match:
optionsBuilder.UseNpgsql(connectionString)
.UseSnakeCaseNamingConvention()
.ReplaceService<IHistoryRepository, SnakeCaseHistoryRepository>();
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.