Ejemplo n.º 1
0
        public ITransaction BeginTransaction(IsolationLevel isolationLevel)
        {
            if (_transaction != null)
            {
                throw new InvalidOperationException("Cannot start transaction.");
            }

            if (!_linqContext.Context.DatabaseExists())
            {
                throw new InvalidOperationException(string.Format("Database {0} is unavailable.", _linqContext.Context.Connection.Database));
            }

            if (_linqContext.Connection.State != ConnectionState.Open)
            {
                _linqContext.Connection.Open();
            }

            IDbTransaction transaction = _linqContext.Connection.BeginTransaction(isolationLevel);

            _linqContext.Transaction            = transaction;
            _transaction                        = new LinqToSqlTransaction(transaction);
            _transaction.TransactionCommitted  += TransactionCommitted;
            _transaction.TransactionRolledback += TransactionRolledback;
            return(_transaction);
        }
Ejemplo n.º 2
0
        private void ReleaseCurrentTransaction()
        {
            if (_transaction != null)
            {
                _transaction.TransactionCommitted  -= TransactionCommitted;
                _transaction.TransactionRolledback -= TransactionRolledback;
                _transaction.Dispose();
            }
            _transaction = null;

            if (_linqContext.Connection.State == ConnectionState.Open)
            {
                _linqContext.Connection.Close();
            }
        }
Ejemplo n.º 3
0
        private void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }
            if (_disposed)
            {
                return;
            }

            if (_transaction != null)
            {
                _transaction.Dispose();
                _transaction = null;
            }
            if (_linqContext != null)
            {
                _linqContext.Dispose();
                _linqContext = null;
            }
            _disposed = true;
        }