Example #1
0
        private IDbContextTransaction BeginTransactionInternal(IsolationLevel?isolationLevel)
        {
            var currentTx = CurrentNestedTransaction;

            if (currentTx != null)
            {
                currentTx = currentTx.BeginTransaction(isolationLevel);
                _logger.Logger.LogInformation("Started a child transaction with id '{TransactionId}' using isolation level '{IsolationLevel}'.", currentTx.TransactionId, isolationLevel);
            }
            else
            {
                var tx = isolationLevel.HasValue ? _innerManager.BeginTransaction(isolationLevel.Value) : _innerManager.BeginTransaction();
                currentTx = new RootNestedDbContextTransaction(_logger, this, _innerManager, tx, null);
                _logger.Logger.LogInformation("Started a root transaction with id '{TransactionId}' using isolation level '{IsolationLevel}'.", currentTx.TransactionId, isolationLevel);
            }

            _transactions.Push(currentTx);

            return(currentTx);
        }
Example #2
0
        private async Task <IDbContextTransaction> BeginTransactionInternalAsync(IsolationLevel?isolationLevel, CancellationToken cancellationToken)
        {
            var currentTx = CurrentNestedTransaction;

            if (currentTx != null)
            {
                currentTx = currentTx.BeginTransaction(isolationLevel);
                _logger.Logger.LogInformation("Started a child transaction with id '{TransactionId}' using isolation level '{IsolationLevel}'.", currentTx.TransactionId, isolationLevel);
            }
            else
            {
                var tx = await(isolationLevel.HasValue
                               ? _innerManager.BeginTransactionAsync(isolationLevel.Value, cancellationToken)
                               : _innerManager.BeginTransactionAsync(cancellationToken))
                         .ConfigureAwait(false);
                currentTx = new RootNestedDbContextTransaction(_logger, this, _innerManager, tx, null);
                _logger.Logger.LogInformation("Started a root transaction with id '{TransactionId}' using isolation level '{IsolationLevel}'.", currentTx.TransactionId, isolationLevel);
            }

            _transactions.Push(currentTx);

            return(currentTx);
        }