public TransactionScope(TransactionMode mode) : base(SessionScopeType.Transactional) { this.mode = mode; ISessionScope previousScope = ScopeUtil.FindPreviousScope(this, mode == TransactionMode.Inherits ? true : false ); if (previousScope != null) { if (previousScope.ScopeType == SessionScopeType.Transactional) { parentTransactionScope = previousScope as TransactionScope; } else { // This is not a safe cast. Reconsider it parentSimpleScope = (AbstractScope) previousScope; foreach(ISession session in parentSimpleScope.GetSessions()) { EnsureHasTransaction(session); } } } }
/// <summary> /// Initializes a new instance of the <see cref="TransactionScope"/> class. /// </summary> /// <param name="mode">Whatever to create a new transaction or inherits an existing one</param> /// <param name="isolationLevel">The transaction isolation level.</param> /// <param name="onDisposeBehavior">The on dispose behavior.</param> public TransactionScope(TransactionMode mode, IsolationLevel isolationLevel, OnDispose onDisposeBehavior) : base(FlushAction.Config, SessionScopeType.Transactional) { this.mode = mode; this.isolationLevel = isolationLevel; this.onDisposeBehavior = onDisposeBehavior; bool preferenceForTransactionScope = mode == TransactionMode.Inherits ? true : false; ISessionScope previousScope = ScopeUtil.FindPreviousScope(this, preferenceForTransactionScope); if (previousScope != null) { if (previousScope.ScopeType == SessionScopeType.Transactional) { parentTransactionScope = previousScope as TransactionScope; } else { // This is not a safe cast. Reconsider it parentSimpleScope = (AbstractScope)previousScope; foreach (ISession session in parentSimpleScope.GetSessions()) { EnsureHasTransaction(session); } } } }