agentleFS
mag1artmag1art/skills/efcore-postgresql/SKILL.md

efcore-postgresql

Skill1 starsChanged 3 months agoApache-2.0View on GitHub

Use for EF Core and PostgreSQL data access, query tuning, migrations, concurrency, and persistence reviews.

The file

Show its rules and text

We split this skill into the rules it gives an agent

20 rules. About 0 are common, 20 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈20

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use for entities, configurations, DbContext, repositories, LINQ queries, migrations, transactions, concurrency, indexes, and …

    line 25
  2. Distinctive:

    Do not use for non-.NET data access, database administration unrelated to application code, or API-only changes with no persistence impact.

    line 29
  3. Distinctive:

    Write the smallest intention-revealing query and inspect generated SQL for important paths.

    line 35
  4. Distinctive:

    Add constraints and indexes in the database model, not only in application checks.

    line 36
  5. Distinctive:

    Test provider-specific behavior against PostgreSQL, not an in-memory fake.

    line 37
  6. Distinctive:

    Run migrations, build, and integration tests.

    line 38
  7. Distinctive:

    Use AsNoTracking for read-only queries.

    line 42
  8. Distinctive:

    Avoid lazy loading and accidental N+1 queries.

    line 44
  9. Distinctive:

    Prefer keyset pagination for large tables.

    line 46
  10. Distinctive:

    Do not expose IQueryable outside the persistence boundary.

    line 47
  11. Distinctive:

    Use ExecuteUpdate and ExecuteDelete deliberately.

    line 48
  12. Distinctive:

    Treat SqlNullValueException as a nullability/model mismatch.

    line 50
  13. Distinctive:

    Use PostgreSQL types intentionally: timestamptz, jsonb, arrays, UUID, and numeric precision.

    line 54
  14. Distinctive:

    Use UTC instants and map them consistently.

    line 55
  15. Distinctive:

    Use unique and partial indexes when business rules require them.

    line 56
  16. Distinctive:

    Use optimistic concurrency explicitly.

    line 57
  17. Distinctive:

    Use EXPLAIN (ANALYZE, BUFFERS) for measured query investigations.

    line 59
  18. Distinctive:

    Keep migrations reviewable and generate idempotent production scripts or bundles.

    line 60
  19. Distinctive:

    Keep transaction boundaries at the use-case level when multiple writes must be atomic.

    line 64
  20. Distinctive:

    Check SQL shape, indexes, nullability, tracking mode, transaction scope, cancellation, migration safety, and real-PostgreSQL integration …

    line 68

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

EF Core and PostgreSQL

When to Use

Use for entities, configurations, DbContext, repositories, LINQ queries, migrations, transactions, concurrency, indexes, and PostgreSQL-specific behavior.

When Not to Use

Do not use for non-.NET data access, database administration unrelated to application code, or API-only changes with no persistence impact.

Workflow

  1. Inspect provider, EF Core version, naming conventions, migrations, nullability, and DbContext lifetime.
  2. Identify whether the operation is a read, tracked update, bulk operation, migration, or transaction.
  3. Write the smallest intention-revealing query and inspect generated SQL for important paths.
  4. Add constraints and indexes in the database model, not only in application checks.
  5. Test provider-specific behavior against PostgreSQL, not an in-memory fake.
  6. Run migrations, build, and integration tests.

Query Rules

  • Use AsNoTracking for read-only queries.
  • Project to DTOs instead of loading complete graphs.
  • Avoid lazy loading and accidental N+1 queries.
  • Apply deterministic ordering and bounded pagination.
  • Prefer keyset pagination for large tables.
  • Do not expose IQueryable outside the persistence boundary.
  • Use ExecuteUpdate and ExecuteDelete deliberately; they bypass change tracking.
  • Pass CancellationToken to every async database call.
  • Treat SqlNullValueException as a nullability/model mismatch.

PostgreSQL Rules

  • Use PostgreSQL types intentionally: timestamptz, jsonb, arrays, UUID, and numeric precision.
  • Use UTC instants and map them consistently.
  • Use unique and partial indexes when business rules require them.
  • Use optimistic concurrency explicitly. With Npgsql, xmin can be a concurrency token; SQL Server rowversion is not portable.
  • Parameterize values and never concatenate user input into SQL.
  • Use EXPLAIN (ANALYZE, BUFFERS) for measured query investigations.
  • Keep migrations reviewable and generate idempotent production scripts or bundles.

Transactions and Reliability

Keep transaction boundaries at the use-case level when multiple writes must be atomic. Consider an outbox for database-plus-message consistency. Handle unique-constraint and serialization failures as expected conflicts where appropriate.

Quality Gate

Check SQL shape, indexes, nullability, tracking mode, transaction scope, cancellation, migration safety, and real-PostgreSQL integration coverage.

Example: Bounded Read and Concurrency

var orders = await db.Orders
    .AsNoTracking()
    .Where(x => x.CustomerId == customerId && x.Id > afterId)
    .OrderBy(x => x.Id)
    .Select(x => new OrderListItem(x.Id, x.Status, x.CreatedAt))
    .Take(Math.Clamp(pageSize, 1, 100))
    .ToListAsync(ct);

var changed = await db.Orders
    .Where(x => x.Id == id && x.Version == expectedVersion)
    .ExecuteUpdateAsync(setters => setters
        .SetProperty(x => x.Status, OrderStatus.Paid)
        .SetProperty(x => x.UpdatedAt, DateTimeOffset.UtcNow), ct);

if (changed == 0)
    throw new ConcurrencyException("The order was changed or deleted.");

The first query uses keyset pagination and projection. ExecuteUpdate bypasses change tracking, so do not expect an already tracked entity to be updated in memory. Use a transaction when several writes must be atomic.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.