add-entity
/add-entity
Add a domain entity/aggregate with EF configuration and a migration to an existing FSH module. Use when adding a new database-backed entity. Pairs with add-feature and create-migration.
- Author
- fullstackhero ↗
- Repository
- dotnet-starter-kit ↗
- Licence
- MIT
- Last repository change
- 09.10.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 09.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Add a domain entity/aggregate with EF configuration and a migration to an existing FSH module. Use when adding a new database-backed entity. Pairs with add-feature and create-migration.
Arguments
/add-entity [ModuleName] [EntityName]
Original author description
Add a domain entity/aggregate with EF configuration and a migration to an existing FSH module. Use when adding a new database-backed entity. Pairs with add-feature and create-migration.
How it works
- Entity — AggregateRoot<Guid> (or BaseEntity<Guid>)
- Domain event — inherit DomainEvent (abstract record)
- EF configuration
- Register in the module DbContext
- Migration
- Checklist
SKILL.md preview
---
name: add-entity
description: Add a domain entity/aggregate with EF configuration and a migration to an existing FSH module. Use when adding a new database-backed entity. Pairs with add-feature and create-migration.
argument-hint: "[ModuleName] [EntityName]"
---
# Add Entity
Rich domain model: `sealed` aggregate, private EF ctor, static factory, behavior via methods, domain
events. DB conventions: `.agents/rules/database.md`.
## Entity — `AggregateRoot<Guid>` (or `BaseEntity<Guid>`)
`BaseEntity<TId>` gives only `Id` + domain-event machinery. Audit/tenant/soft-delete are **opt-in via
marker interfaces** (the base does NOT carry those fields). New ids use **`Guid.CreateVersion7()`**.
```csharp
public sealed class {Entity} : AggregateRoot<Guid>, IHasTenant, IAuditableEntity, ISoftDeletable
{
public string Name { get; private set; } = default!;
public Money Price { get; private set; } = default!;
// IHasTenant
public string TenantId { get; private set; } = default!;
// IAuditableEntity
public DateTimeOffset CreatedOnUtc { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? LastModifiedOnUtc { get; set; }
public string? LastModifiedBy { get; set; }
// ISoftDeletable
public bool IsDeleted { get; set; }
public DateTimeOffset? DeletedOnUtc { get; set; }
public string? DeletedBy { get; set; }
private {Entity}() { } // EF
public static {Entity} Create(string name, Money price)
{
ArgumentException.ThrowIfNullOrWhiteSpace(name);
ArgumentNullException.ThrowIfNull(price);
var entity = new {Entity} { Id = Guid.CreateVersion7(), Name = name.Trim(), Price = price };
entity.AddDomainEvent(DomainEvent.Create((id, ts) =>
new {Entity}CreatedDomainEvent(entity.Id, entity.Name, id, ts)));
return entity;
}
public void Rename(string name)
{
ArgumentException.ThrowIfNullOrWhiteSpace(name);
Name = name.Trim();
}
}
```
Notes: setters are `private set`; `TenantId`/audit/soft-delete members are settable by the framework
(interceptor + Finbuckle) so they aren't `private set`. Use `Guid.CreateVersion7()`, never `Guid.NewGuid()`.
## Domain event — inherit `DomainEvent` (abstract record)
```csharp
public sealed record {Entity}CreatedDomainEvent(
Guid {Entity}Id, string Name, Guid EventId, DateTimeOffset OccurredOnUtc)
: DomainEvent(EventId, OccurredOnUtc);
```
Raise with the `DomainEvent.Create((id, ts) => …)` helper + `AddDomainEvent(...)` (not `QueueDomainEvent`).
## EF configuration
```csharp
public sealed class {Entity}Configuration : IEntityTypeConfiguration<{Entity}>
{
public void Configure(EntityTypeBuilder<{Entity}> builder)
{
ArgumentNullException.ThrowIfNull(builder);
builder.ToTable("{Entities}"); // schema is set once on the DbContext
builder.HasKey(x => x.Id);
builder.Property(x => x.Name).IsRequired().HasMaxLength(200);
// soft-deletable unique field → filter on live rows only
builder.HasIndex(x => x.Name).IsUnique().HasFilter("\"IsDeleted\" = FALSE");
// owned value object
builder.OwnsOne(x => x.Price, m =>
{
m.Property(p => p.Amount).HasColumnName("PriceAmount").HasPrecision(18, 4);
m.Property(p => p.Currency).HasColumnName("PriceCurrency").HasMaxLength(3);
});
builder.Ignore(x => x.DomainEvents);
}
}
```
- **Do NOT add a manual `HasQueryFilter` for soft-delete or tenant** — `BaseDbContext` applies both automatically.
- A child entity reached only via a parent nav-collection needs `builder.Property(x => x.Id).ValueGeneratedNever()` in **its** config, or EF inserts it as `Modified` → 0-row UPDATE. See `database.md`.
## Register in the module DbContext
Add a `DbSet`; configurations are picked up by `ApplyConfigurationsFromAssembly`:
```csharp
public DbSet<{Entity}> {Entities} => Set<{Entity}>();
```
The DbContext already extends `BaseDbContext` and calls `base.OnModelCreating` **last** — don't change that.
## Migration
Use the **create-migration** skill (build first, correct `--context`):
```bash
dotnet ef migrations add Add{Entity} \
--project src/Host/FSH.Starter.Migrations.PostgreSQL \
--startup-project src/Host/FSH.Starter.Api \
--context {X}DbContext
```
## Checklist
- [ ] `sealed`, `AggregateRoot<Guid>` (+ `IHasTenant`/`IAuditableEntity`/`ISoftDeletable` as needed), private ctor, static `Create` using `Guid.CreateVersion7()`
- [ ] Domain event inherits `DomainEvent`; raised via `DomainEvent.Create` + `AddDomainEvent`
- [ ] EF config: no manual soft-delete/tenant filter; `ValueGeneratedNever()` on nav-collection children
- [ ] `DbSet` added; build green; migration created with `--context {X}DbContext`
Versions
| Repository | Score | Licence |
|---|---|---|
| This page · fullstackhero/dotnet-starter-kit | 100 | MIT |
| PrakashShet/PersonalFinance | 100 | MIT |
Database snapshot: 13.11.2026 · package version 7e0f33f14c31 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 1 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100add-feature
Add a vertical-slice feature (command/query + handler + validator + endpoint) to an existing FSH module. Use when adding an API endpoint or business operation to a module that already exists. - 100entity
Define a Protean entity, a domain object with unique identity that is part of an aggregate. Entities are similar to aggregates but don't manage their own persistence; they're always accessed through their parent aggregate. Use when adding objects with identity to an existing… - 95query-patterns
Implement read queries — paginated lists, search/filter/sort, and single-entity fetches — the FSH way (DbContext LINQ + PagedResponse). Use when adding GET endpoints. See also add-feature. - 100add-feature
Adds a feature slice to an existing module end to end, with endpoint, handler, validation, persistence, migration, mapping, tests and an optional page. Use when asked for a new endpoint, use case or page that belongs to a module. - 95nacl-sa-domain
Domain Model through Neo4j graph: DomainEntity, DomainAttribute, Enumeration, relationships. Modes: IMPORT_BA (import from BA layer), CREATE (new entity), MODIFY (change entity), FULL (full module domain model). Use when: create domain model, import BA entities, add domain… - 96add-migration
Create and review a database migration for a finished model change (mapping configuration, generated model artifacts, permission chain, API contract) when the user explicitly invokes /add-migration.