一键导入
dotnet-efcore-guidelines
Apply project EF Core conventions for repositories, DbContext setup, query filters, migrations, and seeded lookup data.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Apply project EF Core conventions for repositories, DbContext setup, query filters, migrations, and seeded lookup data.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Run the canonical build plus all nine per-project test commands from docs/TESTING.md. Never uses solution-level dotnet test.
Create or re-baseline lean, repository-grounded implementation plans and persistent dev docs when users ask for an implementation plan, technical plan, feature plan, refactor plan, or dev-docs workstream.
Senior CTO review workflow for repository-grounded implementation-plan workstreams used before coding.
Create a self-contained HTML artifact focused on a high-quality SVG architecture or system diagram with minimal supporting prose.
Create a pragmatic self-contained HTML plan that organizes the user's plan content visually without expanding the scope unnecessarily.
Create a self-contained HTML artifact for reports, explainers, comparisons, prototypes, or decks when no narrower HTML diagram or plan skill applies.
| name | dotnet-efcore-guidelines |
| description | Apply project EF Core conventions for repositories, DbContext setup, query filters, migrations, and seeded lookup data. |
| type | pattern |
| enforcement | suggest |
| priority | high |
Use this skill when changing repositories, ExploreDbContext, EF configurations, migrations, or PostgreSQL-specific persistence behavior. It keeps runtime tenant isolation and data-shaping rules aligned with Application-layer expectations.
Explore.Persistence/**/*.cs, **/*DbContext.cs, **/Configurations/**/*.cs, Explore.Persistence/Migrations/**/*.cs.add-ef-migration, update-repository-query, add-cqrs-handler.AsNoTracking().SoftDelete and Tenant query filters belong in OnModelCreating, and deleted-row inclusion should prefer IgnoreQueryFilters([QueryFilterNames.SoftDelete]) so tenant isolation stays active.TenantContext and CurrentUserService through property injection, and both can be null during migrations or seeding.LookupTableSeeder missing-row repair, and any migration-dependent lookup row is inserted locally before its backfill; model HasData() stays forbidden while EF Core #36682 applies.IQueryable, which leaks mapping or EF internals beyond Persistence and weakens Application ownership.Tenant filter, which introduces tenant-isolation bugs that are hard to detect.HasData() seeds lookup rows while EF Core #36682 applies, which can break migration generation and leaves dependent backfills ordered after unavailable runtime seed data.public sealed class EventStatusConfiguration : IEntityTypeConfiguration<EventStatus>
{
public void Configure(EntityTypeBuilder<EventStatus> builder)
{
builder.HasQueryFilter("SoftDelete", x => !x.IsDeleted);
builder.HasQueryFilter("Tenant", x => x.TenantId == TenantContext.CurrentTenantId);
builder.Property(x => x.Id).ValueGeneratedNever();
builder.HasIndex(x => x.MasterCode).IsUnique();
}
}
migrationBuilder.InsertData(
table: "event_statuses",
columns: ["id", "master_code", "full_name"],
values: new object[,] { { 1, "DRAFT", "Draft" } });
migrationBuilder.Sql("UPDATE events SET event_status_id = 1 WHERE event_status_id IS NULL;");
public sealed class EventRepository(ExploreDbContext dbContext) : IEventRepository
{
public async Task<IReadOnlyList<Event>> ListAsync(
IQuerySpecification<Event> specification,
CancellationToken cancellationToken)
{
IQueryable<Event> query = dbContext.Events.AsNoTracking();
query = specification.Apply(query);
return await query.ToListAsync(cancellationToken);
}
}
dotnet test --project tests/Event.Architecture.Tests/Event.Architecture.Tests.csproj --configuration Release --verbosity quiet -- --treenode-filter "/*/*/CleanArchitectureTests/*" --minimum-expected-tests 1 --no-progress --maximum-parallel-tests 1dotnet test --project tests/Event.Persistence.IntegrationTests/Event.Persistence.IntegrationTests.csproj --configuration Release --verbosity quietdotnet build --configuration Release --verbosity quiet