ef-core
БесплатноБез исполняемых скриптовНе проверенUse when writing, editing, or reviewing Entity Framework Core code: DbContext classes, entity types, model configuration (conventions, attributes, fluent…
от recyclarr★ 2 180 звёзд на GitHubОб этом скилле
EF Core
Architecture
DbContextis adapter code, never a port. ItsIQueryablesemantics belong to the provider.- Callers depend on a port the application owns, shaped by use-case operations ("mark instance
finished", "list active jobs"). No generic repositories or per-table CRUD;
DbContextalready is the repository and unit of work. - Business rules live in callers of the port. The adapter only translates operations into queries and transactions. Exception: rules that must run atomically in the database (check-and-update) stay in the adapter.
- Domain types are separate from persistence entities. Keys, foreign keys, and other storage-only state stay on entities. EF's mapping constraints (bindable constructors, mutable navigations, reference identity) must not shape domain types.
- Map with a source-generated mapper that fails the build on unmapped members (e.g. Mapperly). Hand-write only conversions it cannot express (serialization, derived values).
Modeling
Configuration precedence: conventions, then EF attributes, then fluent API. Use the first that expresses the intent; never restate a convention.
- Know the conventions:
- Key:
Idor<Type>Id. - Foreign key:
<Navigation><Key>,<Navigation>Id,<Principal><Key>,<Principal>Id. Name FK properties to match instead of configuringHasForeignKey. - Table: the
DbSetproperty name. - Required relationships cascade on delete; optional ones do not.
- Nullable reference types set column nullability; do not add
[Required]orIsRequired().
- Key:
- Attributes on persistence entities:
[PrimaryKey],[Index],[EntityTypeConfiguration]. - Fluent API only for what attributes cannot express (relationship details,
AutoInclude). Split intoIEntityTypeConfiguration<T>whenOnModelCreatinggrows; do not rely onApplyConfigurationsFromAssemblyordering. - Type-wide rules (enum storage, converters) go in
ConfigureConventions. Write a custom convention only when pre-convention configuration cannot express the rule. - Value objects and JSON columns: complex types (
ComplexProperty,[ComplexType],ToJson()), not owned types. Keep them immutable. - A mutable collection behind a value converter needs a
ValueComparer; prefer immutable types. - Do not use records as entity types; change tracking depends on reference identity.
DbContext lifetime
- One short-lived context per unit of work; dispose it. Never share one across threads or run parallel operations on it. Await each call before the next.
- Use
IDbContextFactory<T>when no DI scope matches the unit of work (background services, multiple units per scope). Use pooling only after measuring. - Seal
DbContextclasses. - After an EF
InvalidOperationException, discard the context.
Querying and saving
- Reads: project with
Selectinto the exact shape needed. Projections fetch only needed columns, are untracked, and avoid cartesian explosion from multiple collectionIncludes. MapperlyIQueryableprojections qualify; check its documented projection limits. - When loading entities read-only, use
AsNoTracking. - No lazy loading. Load related data explicitly; use
AsSplitQuerywhen including sibling collections. - Paginate with a fully unique ordering; prefer keyset pagination over
Skip/Take. - Keep translation in the database. Switch to client evaluation explicitly (
AsEnumerable) only after filtering. - Batch changes into one
SaveChanges; do not save inside loops. ExecuteUpdate/ExecuteDeletebypass the change tracker and run immediately in their own transaction. Do not mix them with tracked changes in one unit of work; wrap several in an explicit transaction when they must be atomic.- Use concurrency tokens where concurrent writers can conflict; handle
DbUpdateConcurrencyException. - Escalate warnings that indicate bugs with
ConfigureWarnings(w => w.Throw(...)).
Migrations
- Commit migrations; review every generated one. Renames scaffold as drop and add; replace with
RenameColumn/RenameTable. Never reference entity types or the context inside a migration. - Never combine
EnsureCreatedwith migrations. - Never remove a migration applied outside a local database; add a corrective one.
- Multiple contexts in one database: separate migration sets and
MigrationsHistoryTablenames. Multiple providers: one migration set per provider, each in its own assembly. - Seed with
UseSeedingandUseAsyncSeeding, both implemented and idempotent.HasDataonly for static reference data with fixed keys. - A test per context diffs the last migration's snapshot against the current model
(
IMigrationsModelDiffer.GetDifferences) and asserts no operations, so failures name the missing changes. Build the context without migrating; since EF9, migrating with an outdated model throws. - Write expand/contract migrations: each must work with the previous app version. Additive changes ship
Установить ef-core в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл ef-core?
Use when writing, editing, or reviewing Entity Framework Core code: DbContext classes, entity types, model configuration (conventions, attributes, fluent API), persistence ports and their EF adapters, LINQ queries, SaveChanges or ExecuteUpdate/ExecuteDelete, migrations and seeding, domain-to-entity mapping, or tests that touch a database. Triggers on phrases like "add an entity", "add a migration", "DbContext", "EF Core query", "persistence layer", "repository".
Как установить скилл ef-core?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл ef-core запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic