Instruction file imported from sametkarademir/codium-dotnet-api-template (
.cursor/rules/entity-configuration.mdc). Copyright stays with the author.
Entity Configuration Rules
-
Location and naming
- Place configurations in
EntityConfigurations/withinCodium.Template.EntityFrameworkCore. - Name each configuration
{Entity}Configurationand implementIEntityTypeConfiguration<{Entity}>.
- Place configurations in
-
Global configuration and table naming
- Always call
builder.ApplyGlobalEntityConfigurations();at the start ofConfigure. - Map to tables using:
builder.ToTable(ApplicationConsts.DbTablePrefix + "{Entities}", ApplicationConsts.DbSchema);- Follow the existing pluralization pattern (e.g.
"Users","Roles","Sessions").
- Always call
-
Property configuration
- Use
{Entity}ConstsfromDomain.Sharedfor string max lengths and defaults. - Mark required properties with
.IsRequired();, optional ones with.IsRequired(false);. - Configure sensible defaults for booleans and counters (see
UserConfigurationas a template).
- Use
-
Indexes and uniqueness
- Create indexes for normalized identifiers (email, name, etc.) and enforce uniqueness where required.
- When using soft delete, add filters similar to the existing
"IsDeleted" = FALSEpattern.
-
Relationships
- Configure relationships explicitly using
HasOne/WithMany/HasForeignKey. - Set appropriate delete behavior (
DeleteBehavior.CascadeorRestrict) to match domain invariants.
- Configure relationships explicitly using
-
Readability and consistency
- Group configuration sections logically: table, indexes, scalar properties, relationships.
- Use the existing
UserConfiguration,RoleConfiguration, andSessionConfigurationas reference examples.