Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

ef-core

БесплатноБез исполняемых скриптовНе проверен

Use when writing, editing, or reviewing Entity Framework Core code: DbContext classes, entity types, model configuration (conventions, attributes, fluent…

recyclarrот recyclarr★ 2 180 звёзд на GitHub

Об этом скилле

EF Core

Architecture

  • DbContext is adapter code, never a port. Its IQueryable semantics 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; DbContext already 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: Id or <Type>Id.
    • Foreign key: <Navigation><Key>, <Navigation>Id, <Principal><Key>, <Principal>Id. Name FK properties to match instead of configuring HasForeignKey.
    • Table: the DbSet property name.
    • Required relationships cascade on delete; optional ones do not.
    • Nullable reference types set column nullability; do not add [Required] or IsRequired().
  • Attributes on persistence entities: [PrimaryKey], [Index], [EntityTypeConfiguration].
  • Fluent API only for what attributes cannot express (relationship details, AutoInclude). Split into IEntityTypeConfiguration<T> when OnModelCreating grows; do not rely on ApplyConfigurationsFromAssembly ordering.
  • 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 DbContext classes.
  • After an EF InvalidOperationException, discard the context.

Querying and saving

  • Reads: project with Select into the exact shape needed. Projections fetch only needed columns, are untracked, and avoid cartesian explosion from multiple collection Includes. Mapperly IQueryable projections qualify; check its documented projection limits.
  • When loading entities read-only, use AsNoTracking.
  • No lazy loading. Load related data explicitly; use AsSplitQuery when 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/ExecuteDelete bypass 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 EnsureCreated with migrations.
  • Never remove a migration applied outside a local database; add a corrective one.
  • Multiple contexts in one database: separate migration sets and MigrationsHistoryTable names. Multiple providers: one migration set per provider, each in its own assembly.
  • Seed with UseSeeding and UseAsyncSeeding, both implemented and idempotent. HasData only 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
Полный SKILL.md на GitHub

Установить 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), без исполняемых скриптов.

Похожие скиллы

Сравнить ef-core с