efcore-patterns

efcore-patterns is a skill for Claude Code, Codex from Aaronontheweb/dotnet-skills. It costs 35 tokens per session (3,882 once invoked), scanned A, original, MIT.

Guidance for using Entity Framework Core, a .NET library that maps application code to database data. It covers read queries, related data, database migrations, retries, and updates.

In plain words
What is it for?
Use it when setting up EF Core, improving query performance, managing database schema changes, or debugging update and related-data loading issues.
Why use it?
It helps prevent slow queries, unwanted change tracking, migration mistakes, and failures during temporary database problems. It also explains when read-only queries need to opt into tracking.

Skill for Claude CodeCodex

Part of the dotnet-skills plugin — 36 skills, 6 agents shipped together

About the project

.NET Skills is an AI coding plugin that provides skills and specialized guidance for professional .NET development, covering areas such as C#, Akka.NET, Aspire, Entity Framework Core, testing, and performance. .NET developers use it with coding assistants to apply production-oriented patterns while building and maintaining applications. The catalogue contains the plugin’s skills, agents, and instructions.

Aaronontheweb/dotnet-skills · 1,140 stars · on GitHub

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/aaronontheweb/dotnet-skills/efcore-patterns
Any agent
npx skills add Aaronontheweb/dotnet-skills --skill efcore-patterns
Clone the repo
git clone --depth 1 https://github.com/Aaronontheweb/dotnet-skills

Made for: Claude Code, Codex.

Or install dotnet-skills, the plugin that ships this one along with the rest of its 36 skills, 6 agents.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for efcore-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/aaronontheweb/dotnet-skills/efcore-patterns.svg)](https://agentmods.dev/skills/aaronontheweb/dotnet-skills/efcore-patterns)
Your own site
<a href="https://agentmods.dev/skills/aaronontheweb/dotnet-skills/efcore-patterns"><img src="https://agentmods.dev/badge/skills/aaronontheweb/dotnet-skills/efcore-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 35 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,882 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00035 $0.03882
Opus 5 $0.00017 $0.01941
Sonnet 5 $0.00007 $0.00776
Haiku 4.5 $0.00003 $0.00388

Measured 5d ago against content hash 908a5e366c02, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

efcore-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

Copies of this mod

1 near-identical copy found in the catalogue:

skills/efcore-patterns/SKILL.md · 630 lines

How it starts

The opening of the file, as written. The whole thing — 630 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Entity Framework Core Patterns

When to Use This Skill

Use this skill when:

  • Setting up EF Core in a new project
  • Optimizing query performance
  • Managing database migrations
  • Integrating EF Core with .NET Aspire
  • Debugging change tracking issues
  • Loading multiple navigation collections efficiently (query splitting)

Core Principles

  1. NoTracking by Default - Most queries are read-only; opt-in to tracking
  2. Never Edit Migrations Manually - Always use CLI commands
  3. Dedicated Migration Service - Separate migration execution from application startup
  4. ExecutionStrategy for Retries - Handle transient database failures
  5. Explicit Updates - When NoTracking, explicitly mark entities for update

Pattern 1: NoTracking by Default

Configure your DbContext to disable change tracking by default. This improves performance for read-heavy workloads.

public class ApplicationDbContext : DbContext
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options)
    {
        // Disable change tracking by default for better performance on read-only queries
        // Use .AsTracking() explicitly for queries that need to track changes
        ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
    }

    public DbSet<Order> Orders => Set<Order>();
    public DbSet<Customer> Customers => Set<Customer>();
}

When NoTracking is Active

Read-only queries work normally:

// ✅ Fast read - no tracking overhead
var orders = await dbContext.Orders
    .Where(o => o.Status == OrderStatus.Pending)
    .ToListAsync();

Writes require explicit handling:

// ❌ WRONG - Entity not tracked, SaveChanges does nothing
var order = await dbContext.Orders.FirstOrDefaultAsync(o => o.Id == orderId);
order.Status = OrderStatus.Shipped;
await dbContext.SaveChangesAsync(); // Nothing happens!

// ✅ CORRECT - Explicitly mark entity for update
var order = await dbContext.Orders.FirstOrDefaultAsync(o => o.Id == orderId);
order.Status = OrderStatus.Shipped;
dbContext.Orders.Update(order); // Marks entire entity as modified
await dbContext.SaveChangesAsync();

// ✅ ALSO CORRECT - Use AsTracking() for the query
var order = await dbContext.Orders
    .AsTracking()
    .FirstOrDefaultAsync(o => o.Id == orderId);
order.Status = OrderStatus.Shipped;
await dbContext.SaveChangesAsync(); // Works!

Read the full file on GitHub · 630 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 630 lines · 35 tokens per session scan A 908a5e366c02

Subscribe to this mod's changes

efcore-patterns is a skill published in the GitHub repository Aaronontheweb/dotnet-skills (1,140 stars, last pushed 28d ago), licensed MIT. It adds 35 tokens to every session and 3,882 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

azure-resource-manager-postgresql-dotnet

Azure PostgreSQL Flexible Server SDK for .NET. Database management for PostgreSQL Flexible Server deployments. Use for creating servers, databases, firewall rules, configurations, backups, and high availability. Triggers: "PostgreSQL", "PostgreSqlFlexibleServer", "PostgreSQL Flexible Server", "Azure Database for…

microsoft/skills · 97 tokens

optimizing-ef-core-queries

Optimize and improve the performance of slow Entity Framework Core (EF Core) queries: make them generate less SQL, make fewer database round-trips, and return results faster. Use whenever an EF Core or DbContext query or data-access path is slow or should be made faster — whether or not EF Core owns the database…

dotnet/skills · 86 tokens

entity-framework-core

Design, tune, or review EF Core data access with proper modeling, migrations, query translation, performance, and lifetime management for modern .NET applications. USE FOR: DbContext, migrations, model configuration, EF queries, tracking, loading, performance, transactions, and EF6 migration decisions. DO NOT USE FOR…

managedcode/dotnet-skills · 110 tokens

entity-framework6

Maintain or migrate EF6-based applications with realistic guidance on what to keep, what to modernize, and when EF Core is or is not the right next step. USE FOR: EF6 codebases; runtime versus ORM migration decisions; EDMX, code-first, ObjectContext, and legacy data-access review. DO NOT USE FOR: unrelated stacks…

managedcode/dotnet-skills · 114 tokens

ef-core

Entity Framework Core patterns for .NET 10. Covers DbContext configuration, migrations workflow, interceptors, compiled queries, ExecuteUpdateAsync, ExecuteDeleteAsync, value converters, and query optimization. Load this skill when working with databases, writing queries, managing schema changes, or when the user…

codewithmukesh/dotnet-claude-kit · 113 tokens

migrate

Guided, safe migration workflow covering EF Core schema migrations, .NET version upgrades, and NuGet dependency updates — each with rollback strategies and verification steps. Invoke when: "add migration", "update database", "create migration", "schema change", "new table", "rename column", "upgrade nuget", "update…

codewithmukesh/dotnet-claude-kit · 82 tokens