Skip to content
Back to skills

Efcore Patterns

ASecurity

Designs and diagnoses Entity Framework Core queries, tracking, model configuration, DbContext lifetimes, transactions, concurrency, and migrations. Use when EF Core behavior is central; do not use for non-EF data access (use performance-review or csharp-best-practices) or broad API review.

  • 7 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 4, 2026
ai-agentsc#sqlexpresstestingcode-reviewapidatabasesecurityperformance

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned December 4, 2026

npx -y skills add k4ndev/claude-code-dotnet --skill efcore-patterns --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Efcore Patterns?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Efcore Patterns
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/k4ndev-efcore-patterns/badge)](https://www.skillsdirectory.com/skills/k4ndev-efcore-patterns)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: efcore-patterns
description: Designs and diagnoses Entity Framework Core queries, tracking, model configuration, DbContext lifetimes, transactions, concurrency, and migrations. Use when EF Core behavior is central; do not use for non-EF data access (use performance-review or csharp-best-practices) or broad API review.
---

# EF Core Patterns

## Purpose
Make EF Core persistence correct and efficient without assuming provider behavior or confusing test doubles with relational semantics.

## Scope
LINQ-to-Entities, tracking, entity configuration, `DbContext`, transactions, optimistic concurrency, query plans, and EF migrations.

## When to use
- A task references EF Core queries, `DbContext`, `SaveChanges`, migrations, provider translation, or tracking.
- A performance question involves an EF query; coordinate with `performance-review` when measurement is needed.

## Do not use for
- Dapper/ADO.NET-only code: use `performance-review` / `csharp-best-practices` as appropriate.
- Entire HTTP endpoint contracts: use `api-contract-review` or `dotnet-code-review` when review intent exists.

## Required context
Identify EF Core and provider versions, database engine, context lifetime/registration, entity configuration, migrations applied in each environment, query workload/data size, and test provider.

## Workflow
1. Inspect LINQ expression and generated SQL for nontrivial translation; confirm server-side filtering/projection and inspect query plan when performance is the concern.
2. Project only required fields; use no-tracking for read-only paths when identity resolution/change tracking are not needed.
3. Bound result sets and use deterministic keyset/offset pagination appropriate to ordering and product requirements.
4. Check N+1, cartesian expansion, split-query trade-offs, accidental client-side work, repeated enumeration, and parameterization.
5. Keep `DbContext` scoped to a unit of work; never run parallel operations on the same context instance.
6. Define transaction boundaries for the full business operation. Use concurrency tokens when lost updates matter; inspect retry execution strategy interactions with manual transactions.
7. Treat migration SQL as provider- and deployment-specific: inspect locks, defaults, data backfill, rollback, and expand/contract compatibility.
8. Never edit an applied migration or execute a production migration without explicit authorization. Test relational semantics with the real provider or a compatible relational test database; EF InMemory is not a relational substitute.

## Decision rules
- Do not add `Include` for fields that projection can serve; do not remove tracking where updates or identity semantics depend on it.
- Performance claims require SQL/plan/measurement evidence; correctness findings may be explained from verified semantics.
- For multi-resource atomic writes, an EF transaction alone cannot make a broker/API side effect atomic; use an outbox design when required.

## Expected output format
Describe provider/version assumptions, query or unit-of-work behavior, corrected code/SQL shape, operational migration risks, and targeted relational tests. State when SQL or plan was not inspected.

## Common mistakes
- Assuming `AsNoTracking` is always faster, using an unbounded query, sharing a context across tasks, relying on InMemory for relational behavior, or hand-editing deployed migrations.

## Edge cases
- Global query filters may affect admin/soft-delete behavior; verify intentional bypasses.
- `ExecuteUpdate`/`ExecuteDelete` bypass change tracking and may bypass domain hooks; verify target EF version and invariants.
- Retrying transactions can repeat delegate side effects; keep retried work idempotent and database-contained.

## Examples
See [EF Core examples](examples.md) for bounded projection and concurrency-safe updates.

## Test scenarios
- Positive: “Diagnose this EF Core list endpoint's N+1 and propose an integration test using SQL Server.”
- Negative: “What is C# nullable reference type syntax?” routes to `csharp-best-practices`.
- Boundary: query speed issue selects this skill and `performance-review`; a DB-free LINQ-to-Objects question does not.

## Related skills
`performance-review`, `dotnet-code-review`, `api-contract-review`, `messaging-patterns`, `testing-quality`, `security-audit`.

Files in this skill

  • SKILL.md4.2 KB
  • examples.md2.3 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.