private async Task <IDbContextTransaction> BeginTransactionWithNoPreconditionsAsync(IsolationLevel isolationLevel, CancellationToken cancellationToken = default(CancellationToken)) { DbTransaction dbTransaction = null; if (DbConnection is MySqlConnection mySqlConnection) { dbTransaction = await mySqlConnection.BeginTransactionAsync(isolationLevel).ConfigureAwait(false); } else { dbTransaction = DbConnection.BeginTransaction(isolationLevel); } CurrentTransaction = new MySqlRelationalTransaction( this, dbTransaction, Dependencies.TransactionLogger, transactionOwned: true); Dependencies.TransactionLogger.TransactionStarted( this, dbTransaction, CurrentTransaction.TransactionId, DateTimeOffset.UtcNow); return(CurrentTransaction); }
/// <summary> /// Specifies an existing <see cref="DbTransaction" /> to be used for database operations. /// </summary> /// <param name="transaction"> The transaction to be used. </param> public override IDbContextTransaction UseTransaction(DbTransaction transaction) { if (transaction == null) { if (CurrentTransaction != null) { CurrentTransaction = null; } } else { if (CurrentTransaction != null) { throw new InvalidOperationException(RelationalStrings.TransactionAlreadyStarted); } Open(); CurrentTransaction = new MySqlRelationalTransaction( this, transaction, Dependencies.TransactionLogger, transactionOwned: false); Dependencies.TransactionLogger.TransactionUsed( this, transaction, CurrentTransaction.TransactionId, DateTimeOffset.UtcNow); } return(CurrentTransaction); }
public IDbContextTransaction UseTransaction(DbTransaction transaction) { if (transaction == null) { if (CurrentTransaction != null) { CurrentTransaction = null; DoClose(); } } else { var mySqlTransaction = transaction as MySqlTransaction; if (mySqlTransaction == null) { throw new InvalidCastException("transaction must be of the type MySqlTransaction"); } if (CurrentTransaction != null) { throw new InvalidOperationException(RelationalStrings.TransactionAlreadyStarted); } DoOpen(); CurrentTransaction = new MySqlRelationalTransaction(this, mySqlTransaction, false); } return(CurrentTransaction); }
private async Task <IDbContextTransaction> BeginTransactionWithNoPreconditionsAsync( IsolationLevel isolationLevel, CancellationToken cancellationToken = default(CancellationToken) ) { CurrentTransaction = new MySqlRelationalTransaction(this, await MySqlDbConnection.BeginTransactionAsync(isolationLevel, cancellationToken).ConfigureAwait(false), true); return(CurrentTransaction); }
private IDbContextTransaction BeginTransactionWithNoPreconditions(IsolationLevel isolationLevel) { Check.NotNull(_logger, nameof(_logger)); _logger.LogDebug( RelationalEventId.BeginningTransaction, isolationLevel, il => RelationalStrings.RelationalLoggerBeginningTransaction(il.ToString("G"))); // ReSharper disable once AssignNullToNotNullAttribute CurrentTransaction = new MySqlRelationalTransaction(this, MySqlDbConnection.BeginTransaction(isolationLevel) as MySqlTransaction, _logger, true); return(CurrentTransaction); }
private async Task <IDbContextTransaction> BeginTransactionWithNoPreconditionsAsync( IsolationLevel isolationLevel, CancellationToken cancellationToken = default(CancellationToken) ) { Check.NotNull(_logger, nameof(_logger)); _logger.LogDebug( RelationalEventId.BeginningTransaction, isolationLevel, il => RelationalStrings.RelationalLoggerBeginningTransaction(il.ToString("G"))); CurrentTransaction = new MySqlRelationalTransaction(this, await MySqlDbConnection.BeginTransactionAsync(isolationLevel, cancellationToken).ConfigureAwait(false), _logger, true); return(CurrentTransaction); }
private IDbContextTransaction BeginTransactionWithNoPreconditions(IsolationLevel isolationLevel) { // ReSharper disable once AssignNullToNotNullAttribute CurrentTransaction = new MySqlRelationalTransaction(this, MySqlDbConnection.BeginTransaction(isolationLevel) as MySqlTransaction, true); return(CurrentTransaction); }