Esempio n. 1
0
        public virtual IDbContextTransaction UseTransaction(DbTransaction transaction)
        {
            if (transaction == null)
            {
                if (CurrentTransaction != null)
                {
                    CurrentTransaction = null;

                    Close();
                }
            }
            else
            {
                if (CurrentTransaction != null)
                {
                    throw new InvalidOperationException(RelationalStrings.TransactionAlreadyStarted);
                }

                Open();

                CurrentTransaction = new RelationalTransaction(this, transaction, _logger, transactionOwned: false);
            }

            return(CurrentTransaction);
        }
Esempio n. 2
0
        public virtual IRelationalTransaction UseTransaction(DbTransaction transaction)
        {
            if (transaction == null)
            {
                if (Transaction != null)
                {
                    Transaction = null;

                    Close();
                }
            }
            else
            {
                if (Transaction != null)
                {
                    throw new InvalidOperationException(RelationalStrings.TransactionAlreadyStarted);
                }

                Open();

                Transaction = new RelationalTransaction(this, transaction, /*transactionOwned*/ false, _logger);
            }

            return(Transaction);
        }
Esempio n. 3
0
        private IRelationalTransaction BeginTransactionWithNoPreconditions(IsolationLevel isolationLevel)
        {
            _logger.BeginningTransaction(isolationLevel);

            Transaction = new RelationalTransaction(this, DbConnection.BeginTransaction(isolationLevel), /*transactionOwned*/ true, _logger);

            return(Transaction);
        }
Esempio n. 4
0
        private IDbContextTransaction BeginTransactionWithNoPreconditions(IsolationLevel isolationLevel)
        {
            Check.NotNull(_logger, nameof(_logger));

            _logger.LogDebug(
                RelationalLoggingEventId.BeginningTransaction,
                isolationLevel,
                il => RelationalStrings.RelationalLoggerBeginningTransaction(il.ToString("G")));

            CurrentTransaction
                = new RelationalTransaction(
                      this,
                      DbConnection.BeginTransaction(isolationLevel),
                      _logger,
                      transactionOwned: true);

            return(CurrentTransaction);
        }
        public void GetDbTransaction_returns_the_DbTransaction()
        {
            var dbConnection  = new FakeDbConnection(ConnectionString);
            var dbTransaction = new FakeDbTransaction(dbConnection);

            var connection = new FakeRelationalConnection(
                CreateOptions(new FakeRelationalOptionsExtension {
                Connection = dbConnection
            }));

            var transaction = new RelationalTransaction(
                connection,
                dbTransaction,
                new ListLogger(new List <Tuple <LogLevel, string> >()),
                false);

            Assert.Equal(dbTransaction, transaction.GetDbTransaction());
        }
        public virtual IRelationalTransaction UseTransaction(DbTransaction transaction)
        {
            if (transaction == null)
            {
                if (Transaction != null)
                {
                    Transaction = null;

                    Close();
                }
            }
            else
            {
                if (Transaction != null)
                {
                    throw new InvalidOperationException(Strings.TransactionAlreadyStarted);
                }

                Open();

                Transaction = new RelationalTransaction(this, transaction, /*transactionOwned*/ false, _logger.Value);
            }

            return Transaction;
        }
        private IRelationalTransaction BeginTransactionWithNoPreconditions(IsolationLevel isolationLevel)
        {
            _logger.Value.BeginningTransaction(isolationLevel);

            Transaction = new RelationalTransaction(this, DbConnection.BeginTransaction(isolationLevel), /*transactionOwned*/ true, _logger.Value);

            return Transaction;
        }
        private IRelationalTransaction BeginTransactionWithNoPreconditions(IsolationLevel isolationLevel)
        {
            Check.NotNull(_logger, nameof(_logger));

            _logger.LogVerbose(
                RelationalLoggingEventId.BeginningTransaction,
                isolationLevel,
                il => RelationalStrings.RelationalLoggerBeginningTransaction(il.ToString("G")));

            Transaction
                = new RelationalTransaction(
                    this,
                    DbConnection.BeginTransaction(isolationLevel),
                     _logger,
                    transactionOwned: true);

            return Transaction;
        }