public async Task CommitTransactionAsync(IDbContextTransaction transaction) { transaction.ThrowIfNull(); if (transaction != _currentTransaction) { throw new InvalidOperationException($"Transaction {transaction.TransactionId} is not current"); } try { await SaveChangesAsync(); transaction.Commit(); } catch { RollbackTransaction(); throw; } finally { if (_currentTransaction.HasValue()) { _currentTransaction.Dispose(); _currentTransaction = null; } } }