Docs / MooTransaction Reference

MooTransaction Reference

Role#

MooTransaction represents an active SQL Server transaction created by db.BeginTransactionAsync(...) where db is a MooDbContext.

Properties#

  • Sql : MooSql
  • Bulk : MooBulk

Main methods#

</> C#
Task<int> ExecuteAsync(...)
Task<T> ScalarAsync<T>(...)
Task<T?> SingleAsync<T>(...)
Task<T?> SingleAsync<T>(..., Func<SqlDataReader, T> map, ...)
Task<List<T>> ListAsync<T>(...)
Task<List<T>> ListAsync<T>(..., Func<SqlDataReader, T> map, ...)
Task<TResult> QueryMultipleAsync<TResult>(..., Func<IMooMultiReader, TResult> read, ...)
Task CommitAsync(...)
ValueTask DisposeAsync()

Key points#

  • all commands share the same connection and SQL transaction
  • MooTransaction should normally be used with await using
  • disposing an uncommitted transaction rolls it back automatically
  • disposing the transaction releases the underlying SQL transaction
  • if the transaction owns its connection, disposing it also disposes that connection
  • if a caller-supplied SqlConnection is used, it is not disposed by the transaction
  • once committed, that transaction instance is complete and cannot be reused