ef-core-patterns
Skill5 starsChanged 6 days agoMITView on GitHub
EF Core best practices reference — safe migrations, query optimization, configuration patterns, and common pitfalls.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- DIL8654/claude-code-dotnet-templatetheir own version, first seen Mar 21, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- DIL8654/claude-code-dotnet-template★ 8same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository15 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- aspnet-api-patternsSkill
- authenticationSkill
- cachingSkill
- clean-architectureSkill
- convention-learnerSkill
- dddSkill
- dotnet-project-initSkill
- error-handlingSkill
- loggingSkill
- modern-csharpSkill
- opentelemetrySkill
- resilienceSkill
- testing-dotnetSkill
- vertical-sliceSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. About 0 are common, 3 are distinctive, and 10 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
10
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 31
Never hand-write a migration from scratch — the model snapshot would drift
- Distinctive: line 36
Keep migrations small and reversible
- Very specific: line 37
Use migrationBuilder.Sql() for data migrations, not EF operations
- Very specific: line 64
Use AsNoTracking() for read-only queries
- Very specific: line 65
Use projections (Select) to fetch only needed columns
- Very specific: line 66
Use Include with ThenInclude for eager loading (avoid N+1)
- Very specific: line 67
Use split queries for many includes: .AsSplitQuery()
- Very specific: line 68
Use ExecuteUpdateAsync / ExecuteDeleteAsync for bulk operations (EF 7+)
- Very specific: line 71
Don't call ToList() before filtering (materializes entire table)
- Very specific: line 72
Don't use Count() when you need Any()
- Distinctive: line 73
Don't load navigation properties you don't need
- Very specific: line 74
Don't use FromSqlRaw with string interpolation (SQL injection risk)
- Very specific: line 75
Don't forget CancellationToken on async queries
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
EF Core Patterns
Reference material for EF Core development.
Migration Safety
Safe Operations
- Adding a new table
- Adding a nullable column
- Adding a column with a default value
- Adding an index
- Renaming (with
migrationBuilder.RenameColumn— preserves data)
Dangerous Operations (require confirmation)
- Dropping a column (data loss)
- Changing column type (potential data truncation)
- Adding NOT NULL column without default (fails on existing rows)
- Dropping a table (data loss)
- Removing an index (performance impact)
Migration Best Practices
- One migration per logical change
- Generate with
dotnet ef migrations add, then review and adjust the generatedUp/Down(a rename scaffolded as drop + add must becomeRenameColumn; data moves go inSql()). Never hand-write a migration from scratch — the model snapshot would drift dotnet ef database updatehas no dry-run: review the SQL withdotnet ef migrations script <from> <to>(--idempotentfor scripts run against unknown state)dotnet ef migrations has-pending-model-changes(EF Core 8+) fails when the model has changed since the last migration — use it as a CI gate- Keep migrations small and reversible
- Use
migrationBuilder.Sql()for data migrations, not EF operations
Configuration Patterns
Fluent API (preferred)
public class UserConfiguration : IEntityTypeConfiguration<User>
{
public void Configure(EntityTypeBuilder<User> builder)
{
builder.HasKey(u => u.Id);
builder.Property(u => u.Email).HasMaxLength(256).IsRequired();
builder.HasIndex(u => u.Email).IsUnique();
builder.HasMany(u => u.Orders).WithOne(o => o.User).HasForeignKey(o => o.UserId);
}
}DbContext Registration
// In OnModelCreating:
modelBuilder.ApplyConfigurationsFromAssembly(typeof(ApplicationDbContext).Assembly);Query Optimization
Do
- Use
AsNoTracking()for read-only queries - Use projections (
Select) to fetch only needed columns - Use
IncludewithThenIncludefor eager loading (avoid N+1) - Use split queries for many includes:
.AsSplitQuery() - Use
ExecuteUpdateAsync/ExecuteDeleteAsyncfor bulk operations (EF 7+)
Don't
- Don't call
ToList()before filtering (materializes entire table) - Don't use
Count()when you needAny() - Don't load navigation properties you don't need
- Don't use
FromSqlRawwith string interpolation (SQL injection risk) - Don't forget
CancellationTokenon async queries
See Also
skills/ddd/SKILL.md— value converters and complex properties for DDD entitiesskills/testing-dotnet/SKILL.md— testing queries against the real provider
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

