Esempio n. 1
0
        public DbTransactionScope(IsolationLevel isolationLevel, DbTransactionScopeOption scopeOption = DbTransactionScopeOption.Required)
        {
            IsolationLevel = isolationLevel;
            ScopeOption    = scopeOption;

            Parent  = Root;
            Current = this;

            if (Root == null)
            {
                Root = this;
            }
        }
Esempio n. 2
0
        public void Dispose()
        {
            if (IsAborted)
            {
                return;
            }

            if (this == Root) // Root
            {
                Root = null;

                if (IsCompleted)
                {
                    // Happy scenario:
                    Connections.Do(x => x.Value.Item1.Close());
                }
                else // Root is not completed.
                {
                    IsAborted = true;

                    Connections.Do(x => x.Value.Item2.Rollback());
                    Connections.Do(x => x.Value.Item2.Dispose());
                    Connections.Do(x => x.Value.Item1.Close());
                    TransactionRolledBack?.Invoke(this, EventArgs.Empty);
                }
            }
            else
            {
                Current = Parent;

                if (IsCompleted)
                {
                    // A Sub-transaction has been happily completed.
                    // Just wait for the parent.
                }
                else
                {
                    // A sub transaction is not completed.
                    Root?.Dispose();
                }
            }
        }