コード例 #1
0
ファイル: EFUnitOfWork.cs プロジェクト: zlobur/ncommon
        /// <summary>
        /// Releases the current transaction in the <see cref="EFTransaction"/> instance.
        /// </summary>
        private void ReleaseCurrentTransaction()
        {
            if (_transaction != null)
            {
                _transaction.TransactionCommitted  -= TransactionCommitted;
                _transaction.TransactionRolledback -= TransactionRolledback;
                _transaction.Dispose();
            }
            _transaction = null;

            //Closing the connection once the transaction has completed.
            if (_session.Connection.State == ConnectionState.Open)
            {
                _session.Connection.Close();
            }
        }
コード例 #2
0
ファイル: EFUnitOfWork.cs プロジェクト: zlobur/ncommon
        /// <summary>
        /// Instructs the <see cref="IUnitOfWork"/> instance to begin a new transaction
        /// with the specified isolation level.
        /// </summary>
        /// <param name="isolationLevel">One of the values of <see cref="IsolationLevel"/>
        /// that specifies the isolation level of the transaction.</param>
        /// <returns></returns>
        public ITransaction BeginTransaction(IsolationLevel isolationLevel)
        {
            Guard.Against <InvalidOperationException>(_transaction != null,
                                                      "Cannot begin a new transaction while an existing transaction is still running. " +
                                                      "Please commit or rollback the existing transaction before starting a new one.");

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

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

            _transaction = new EFTransaction(transaction);
            _transaction.TransactionCommitted  += TransactionCommitted;
            _transaction.TransactionRolledback += TransactionRolledback;
            return(_transaction);
        }
コード例 #3
0
ファイル: EFUnitOfWork.cs プロジェクト: zlobur/ncommon
        /// <summary>
        /// Disposes off the managed and unmanaged resources used.
        /// </summary>
        /// <param name="disposing"></param>
        private void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }
            if (_disposed)
            {
                return;
            }

            if (_transaction != null)
            {
                _transaction.Dispose();
                _transaction = null;
            }
            if (_session != null)
            {
                _session.Dispose();
                _session = null;
            }
            _disposed = true;
        }
コード例 #4
0
ファイル: EFUnitOfWork.cs プロジェクト: Chris-Kim/ncommon
        /// <summary>
        /// Instructs the <see cref="IUnitOfWork"/> instance to begin a new transaction
        /// with the specified isolation level.
        /// </summary>
        /// <param name="isolationLevel">One of the values of <see cref="IsolationLevel"/>
        /// that specifies the isolation level of the transaction.</param>
        /// <returns></returns>
        public ITransaction BeginTransaction(IsolationLevel isolationLevel)
        {
            Guard.Against<InvalidOperationException>(_transaction != null,
                                                     "Cannot begin a new transaction while an existing transaction is still running. " +
                                                     "Please commit or rollback the existing transaction before starting a new one.");

            if (_session.Connection.State != ConnectionState.Open)
                _session.Connection.Open();

            IDbTransaction transaction = _session.Connection.BeginTransaction(isolationLevel);
            _transaction = new EFTransaction(transaction);
            _transaction.TransactionCommitted += TransactionCommitted;
            _transaction.TransactionRolledback += TransactionRolledback;
            return _transaction;
        }
コード例 #5
0
ファイル: EFUnitOfWork.cs プロジェクト: Chris-Kim/ncommon
        /// <summary>
        /// Releases the current transaction in the <see cref="EFTransaction"/> instance.
        /// </summary>
        private void ReleaseCurrentTransaction()
        {
            if (_transaction != null)
            {
                _transaction.TransactionCommitted -= TransactionCommitted;
                _transaction.TransactionRolledback -= TransactionRolledback;
                _transaction.Dispose();
            }
            _transaction = null;

            //Closing the connection once the transaction has completed.
            if (_session.Connection.State == ConnectionState.Open)
                _session.Connection.Close();
        }
コード例 #6
0
ファイル: EFUnitOfWork.cs プロジェクト: Chris-Kim/ncommon
        /// <summary>
        /// Disposes off the managed and unmanaged resources used.
        /// </summary>
        /// <param name="disposing"></param>
        private void Dispose(bool disposing)
        {
            if (!disposing) return;
            if (_disposed) return;

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