Guides & Recipes — Transaction
Production patterns for nested savepoint recovery, explicit read-only scopes, and zero-DB unit tests.
Recipe 1: Nested Savepoints with NestedTransactionBehavior.UseSavepoint
Section titled “Recipe 1: Nested Savepoints with NestedTransactionBehavior.UseSavepoint”When an outer ExecuteResultAsync scope calls an inner repository or service method that also invokes ExecuteResultAsync, TransactionOptions.Default uses NestedTransactionBehavior.UseSavepoint automatically. If the inner operation returns Result.Failure(...), only the inner savepoint rolls back while the outer transaction remains open to decide recovery or final rollback.
Recipe 2: Explicit Read-Only Transactions (TransactionOptions.ReadOnlyMode)
Section titled “Recipe 2: Explicit Read-Only Transactions (TransactionOptions.ReadOnlyMode)”Pass TransactionOptions.ReadOnlyMode (or TransactionOptions.WithTimeout(TimeSpan.FromSeconds(3))) for multi-query reporting endpoints so backends enforce read-only snapshot semantics and bounded lock waits.