コード例 #1
0
        public override void EndTransaction()
        {
            if (Connection.State != ConnectionState.Open)
            {
                throw new InvalidOperationException("Database is not open.");
            }

            if (Interlocked.Decrement(ref transactionCount) > 0)
            {
                return;
            }

            if (currentTransaction == null)
            {
                if (shouldCommit)
                {
                    throw new InvalidOperationException("Transaction missing.");
                }
                return;
            }
            if (shouldCommit)
            {
                currentTransaction.Commit();
                shouldCommit = false;
            }
            else
            {
                currentTransaction.Rollback();
            }
            currentTransaction.Dispose();
            currentTransaction = null;
        }