dotnet-efcore-guidelines

Guides EF Core entity configuration, migrations, query filters, and repository patterns for .NET persistence layers.

7|3|Updated Sep 23, 2025
One-click install
npx skills add https://github.com/islamu-ngo/Event --skill dotnet-efcore-guidelines-islamu-ngo
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: dotnet-efcore-guidelines
Source: https://github.com/islamu-ngo/Event/tree/main/.agents/skills/dotnet-efcore-guidelines
Command: npx skills add https://github.com/islamu-ngo/Event --skill dotnet-efcore-guidelines-islamu-ngo

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? It enforces consistent, tenant-safe, and migration-disciplined EF Core data access in a .NET solution, preventing common mistakes like leaking IQueryable from repositories, disabling tenant filters accidentally, or hand-editing generated migrations. ## Core Features & Use Cases - Persistence Rules: Repositories return entities (never DTOs or IQueryable), read-only paths use AsNoTracking, and named SoftDelete/Tenant query filters stay enabled by default. - Migration Discipline: Covers dotnet ef commands for creating, scripting, removing, and verifying migrations, with rules against editing applied migrations and guidance for multi-provider SQL generation. - Lookup Seeding & Constraints: Defines stable lookup ID/code seeding via LookupTableSeeder, portable semantic constraints, and preflight checks for MariaDB/MySQL non-transactional DDL. - Use Case: When adding a new entity with tenant isolation and soft delete, follow the workflow to lock domain semantics with failing tests, update the IEntityTypeConfiguration, generate per-provider migrations, and verify with architecture and integration tests. ## Quick Start Ask the AI to review or implement an EF Core entity configuration, repository, or migration following the dotnet-efcore-guidelines rules for this project.

Frequently Asked Questions about dotnet-efcore-guidelines

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create and apply EF Core migrations with dotnet ef?▼

Run dotnet ef migrations add with the context, project, and startup-project flags, then review generated SQL via dotnet ef migrations script --idempotent before applying with dotnet ef database update. Never edit applied migrations; create a corrective migration instead.

How do named query filters work in EF Core?▼

Named filters let you attach multiple global filters like SoftDelete and Tenant to one entity and disable them selectively with IgnoreQueryFilters([name]). Keep filters enabled by default; disabling the tenant filter in runtime request paths is usually a security bug.

Should repositories return IQueryable or DTOs in EF Core?▼

Repositories should return entities, never DTOs or IQueryable. Handlers map entities to DTOs with AutoMapper, and read-only queries should use AsNoTracking for better performance.

How do I avoid N+1 queries in EF Core?▼

Use Include and ThenInclude to eager-load related data instead of lazy-loading in loops, and apply AsSplitQuery for large include graphs. Prefer projections with Select when only a subset of columns is needed.

Can I edit or remove an applied EF Core migration?▼

No. Editing or removing applied migrations breaks the migration history other environments depend on. Only unapplied development migrations can be removed with dotnet ef migrations remove; applied ones require a generated corrective migration.

Why should HasData be avoided for lookup table seeding in EF Core?▼

Model HasData is avoided while EF Core issue #36682 applies. Instead, seed lookup rows through an idempotent seeder that repairs missing rows by stable ID, and insert migration-dependent rows with migration-local InsertData before backfill.