Expand description
Transaction handle abstraction.
DbContext::begin_transaction() returns a context-scoped
ITransaction. The handle exposes commit / rollback (which consume
it), savepoint operations, isolation control, and a connection() accessor
used internally by save_changes().
§Control modes
- Manual —
let txn = ctx.begin_transaction().await?; ... txn.commit().await?;The transaction is registered on the context: queries, bulk DML, raw SQL andsave_changes()all use its connection. Commit or rollback explicitly. - Closure —
ctx.use_transaction(|ctx| Box::pin(async move { ... })).await?. Commits onOk, rolls back onErr.
Any handle dropped without commit / rollback is rolled back on a
background task, matching EF Core / ADO.NET Dispose semantics. The
runtime is captured when the handle is created, so dropping it outside a
Tokio context can still schedule the rollback. The rollback is best effort:
it cannot run if the runtime is already shut down, and panic = "abort"
skips Drop entirely.
Structs§
- DbTransaction
- Default
ITransactionimplementation for context-scoped transactions.
Traits§
- ITransaction
- Transaction handle abstracting the connection-level transaction methods.