Ejemplo n.º 1
0
 /// <summary>
 /// Releases the current transaction in the <see cref="NhUnitOfWork"/> instance.
 /// </summary>
 private void ReleaseCurrentTransaction()
 {
     if (_transaction != null)
     {
         _transaction.TransactonComitted -= TransactionCommitted;
         _transaction.TransactionRolledback -= TransactionRolledback;
         _transaction.Dispose();
     }
     _transaction = null;
 }
Ejemplo n.º 2
0
        /// <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)
        {
            Throw.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.");

            _transaction = new NhTransaction(_session.BeginTransaction(isolationLevel));
            _transaction.TransactonComitted += TransactionCommitted;
            _transaction.TransactionRolledback += TransactionRolledback;

            return _transaction;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Disposes off managed resources used by the NHUnitOfWork instance.
        /// </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;
        }