DKNet

DKNet.EfCore.Extensions

Model configuration, seeding, change-tracker helpers and sensitive JSON filtering for .NET developers using EF Core.

✨ Why use it?

🚀 Quick Start

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.

🏗️ Architecture

The host configures AutoConfigModelCustomizer for EF model construction and calls independent snapshot, save and serialization helpers.

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.

🔄 How it works

UseAutoConfigModel stores assemblies, applies entity configurations and global builders, then registers sequences on SQL Server or Npgsql.

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.

🧩 Features