Why this matters
Maintains data consistency under partial failures.
Wrap multi-step writes in a transaction; on failure, roll back and rethrow with context.
Maintains data consistency under partial failures.
Side-by-side examples engineers can pattern-match during review.
await ctx.SaveChangesAsync(); // multiple SaveChanges without transactionawait using var tx = await ctx.Database.BeginTransactionAsync();
// ... multiple updates ...
await ctx.SaveChangesAsync();
await tx.CommitAsync();SaveChanges called multiple times w/o transactionBeginTransaction/Commit with one SaveChangesFrom the same buckets as this rule.
Review SQL/database migrations for operations that can lock large tables or cause downtime. Examples: creating indexes without CONCURRENTLY (Postgres), ALTER COLUMN TYPE on big tables, adding NOT NULL without backfill, long-running updates without batching. Require an online migration strategy (CONCURRENTLY, backfill in batches, dual-write/expand-contract) and a rollback plan.