Model configuration, seeding, change-tracker helpers and sensitive JSON filtering for .NET developers using EF Core.
Use a .NET 10 console project. Install the package, then replace Program.cs with the example.
dotnet new console -f net10.0 -n EfCoreDemo
cd EfCoreDemo
dotnet add package DKNet.EfCore.Extensions
dotnet add package Microsoft.EntityFrameworkCore.Sqlite --version 10.0.12
using Microsoft.EntityFrameworkCore;
using DKNet.EfCore.Extensions.Configurations;
using var connection = new Microsoft.Data.Sqlite.SqliteConnection("Data Source=:memory:");
connection.Open();
var o = new DbContextOptionsBuilder<DemoDb>();
o.UseSqlite(connection).UseAutoConfigModel<DemoDb>();
await using var db = new DemoDb(o.Options);
await db.Database.EnsureCreatedAsync();
var item = new Item { Name = "Coffee" };
db.Add(item);
await db.SaveChangesAsync();
Console.WriteLine(item.Id != Guid.Empty); // True
public sealed class DemoDb(DbContextOptions<DemoDb> options) : DbContext(options)
{
public DbSet<Item> Items => Set<Item>();
}
public sealed class Item : DKNet.EfCore.Abstractions.Entities.Entity
{
public string Name { get; set; } = "";
}
public sealed class ItemConfiguration : DefaultEntityTypeConfiguration<Item>
{
public override void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder<Item> b)
{
base.Configure(b);
b.Property(x => x.Name).HasMaxLength(80);
}
}
Run with dotnet run.
Model customization runs in EF Core model building and delegates to the original provider customizer. Global builder registrations and filter-key metadata are process-wide; seeders, snapshots and JSON filtering are independent opt-ins. The project references Abstractions, Fw.Extensions and EF Core Relational.
The default assembly is the context assembly. Configuration classes introduce their entities; the scan does not map arbitrary plain types. Activation, configuration and provider errors propagate; seeding is configured separately.
IEntityTypeConfiguration<T> implementations and apply DKNet identity, audit and concurrency conventions through a configuration base.IGlobalModelBuilder for model-wide changes and GlobalQueryFilter for per-entity named query filters.IDataSeedingConfiguration implementations and run them through EF Core native seeding callbacks.IEfCoreExceptionHandler.JsonSerializerOptions instance into role-aware omission for properties declared [SensitiveData].