DKNet

Give domain entities an identity

Part of DKNet.EfCore.Abstractions. Use Entity<TKey> for an identity plus event queues, or implement the covariant IEntity<out TKey> contract yourself.

Use the console-project setup in the Quick Start, then replace Program.cs with this example.

using DKNet.EfCore.Abstractions.Entities;

var item = new Product(7, "Coffee");
Console.WriteLine(item); // Product '7'

public sealed class Product(int id, string name) : Entity<int>(id)
{
    public string Name { get; } = name;
}

![Product supplies its integer ID to Entity, whose Id getter and ToString expose that identity.](/DKNet/DKNet.EfCore.Abstractions/diagrams/define-entities.svg)

Entity specializes Entity<Guid>. Parameterless construction leaves Id at its CLR default; supplying an ID calls the protected base constructor. No key is generated by this package.

⚠️ Gotchas & limits