public async Task RollbackTransactionAsync(DbTransaction transaction) { DbConnection connection = transaction.Connection; await transaction.RollbackAsync(); await connection.CloseAsync(); await transaction.DisposeAsync(); await connection.DisposeAsync(); }
public async Task CommitTransactionAsync(DbTransaction transaction) { DbConnection connection = transaction.Connection; await transaction.CommitAsync(); await connection.CloseAsync(); await transaction.DisposeAsync(); await connection.DisposeAsync(); }
private async Task Initialise() { if (_transaction != null) { await _transaction.DisposeAsync(); _transaction = null; ResetRepositories(); } _transaction = await GetDbTransaction(); }
public async Task <int> ExecuteTransactionAsync(Dictionary <string, object> sqlAndParameters, bool disposeConnection = true) { DbTransaction dbTransaction = null; try { await this.OpenDBConnectionAsync(); dbTransaction = await base._dbConnection.BeginTransactionAsync(); int affectedCollumnsNum = 0; foreach (KeyValuePair <string, object> sqlAndParameter in sqlAndParameters) { affectedCollumnsNum += await base._dbConnection.ExecuteAsync(sqlAndParameter.Key, sqlAndParameter.Value, dbTransaction); } await dbTransaction.CommitAsync(); return(affectedCollumnsNum); } catch (DbException e) { await dbTransaction?.RollbackAsync(); disposeConnection = true; throw e; } catch (Exception e) { await dbTransaction?.RollbackAsync(); disposeConnection = true; // TODO: Create a Transaction exception. throw e; } finally { _ = dbTransaction.DisposeAsync(); if (disposeConnection) { _ = base._dbConnection.DisposeAsync(); } } }
/// <summary> /// Clears all the resources associated to the transaction. /// </summary> private async Task ReleaseTransactionAsync() { foreach (var state in _collectionStates.Values) { // IndentityMap is cleared in ReleaseSession() state._concurrent?.Clear(); state._saved?.Clear(); state._updated?.Clear(); state._tracked?.Clear(); state._deleted?.Clear(); state._maps?.Clear(); } _commands?.Clear(); _commands = null; if (_transaction != null) { await _transaction.DisposeAsync(); _transaction = null; } }
public ValueTask DisposeAsync() { return(_transaction.DisposeAsync()); }