/// <summary>
        /// Disposes this transaction. Commits the transaction if this is the parent transaction.
        /// </summary>
        public void Dispose()
        {
            if (!isDisposed)
            {
                // if this is the real transaction that is being disposed, null the current transaction
                if (this.realGlobalTransaction == null)
                {
                    GlobalTransaction.CurrentGlobalTransaction = null;
                }

                // commit all transactions and close the connection
                foreach (IDbTransaction transaction in this.openTransactions.Values)
                {
                    using (IDbConnection connection = transaction.Connection)
                    {
                        using (transaction)
                        {
                            transaction.Commit();
                        }
                    }
                }
                this.openTransactions.Clear();

                isDisposed = true;
            }
        }
 /// <summary>
 /// Private constructor to create global transaction with the given parent transaction
 /// </summary>
 private GlobalTransaction(GlobalTransaction realGlobalTransaction)
 {
     this.realGlobalTransaction = realGlobalTransaction;
 }
        /// <summary>
        /// Begins a global transaction. Creates a new GlobalTransaction if none is already started or returns
        /// a wrapper around existing one if one is already started. DO NOT CALL THIS METHOD DIRECTLY, USE DataAcessManager.StartGlobalTransaction
        /// API instead.
        /// </summary>
        internal static GlobalTransaction BeginGlobalTransaction()
        {
            GlobalTransaction transaction = null;
            if (GlobalTransaction.CurrentGlobalTransaction == null)
            {
                GlobalTransaction.CurrentGlobalTransaction = new GlobalTransaction();
                transaction = GlobalTransaction.CurrentGlobalTransaction;
            }
            else
            {
                // This will only happen when somebody starts a nested global transaction
                // returned global transaction is just a dummy wrapper around main global transaction
                transaction = new GlobalTransaction(GlobalTransaction.CurrentGlobalTransaction);
            }

            return transaction;
        }