Part of DKNet.EfCore.Abstractions. Derive from AuditedEntity<TKey> or its Guid specialization to store audit identity and timestamps.
Use the console-project setup in the Quick Start, then replace Program.cs with this example.
using DKNet.EfCore.Abstractions.Entities;
var invoice = new Invoice("alice");
invoice.MarkPaid("bob");
Console.WriteLine(invoice.LastModifiedBy); // bob
public sealed class Invoice : AuditedEntity
{
public Invoice(string user) => SetCreatedBy(user);
public void MarkPaid(string user) => SetUpdatedBy(user);
}
IAuditedEntity<TKey> combines identity with IAuditedProperties: CreatedBy, CreatedOn, UpdatedBy and UpdatedOn. LastModifiedBy and LastModifiedOn fall back to creation values and are not mapped.
| Argument | Type | Default | Effect |
|---|---|---|---|
createdOn / updatedOn |
DateTimeOffset? |
null |
Use DateTimeOffset.UtcNow when accepted. |
AuditedEntity stores domain-supplied identity. AuditLogs can supply the signed-in user on save; DataAuthorization supplies ownership-based audit identity when no current-user value is available. Those hooks run in the host, rather than in the entity base class.
SetCreatedBy returns immediately when CreatedBy is already nonempty, before validating the new user.SetUpdatedBy ignores an explicitly older timestamp before validating the user. Otherwise blank users throw ArgumentException; omitted times use UTC now.