none
How to Manage Transaction on Business Level? RRS feed

  • Question

  • Let's say I have this class:

    public class Account

    {

    private int money;

    public Account(int money) { this.money = money; }

    public bool Add(int money) { this.money += money; return true; }

    public bool Subtract(int money) { this.money -= money; return this.Money >= 0; }

    public int Money { get { return this.money; } }

    }

     

    and want to do something like this (it's only schematic):

    private void button1_Click(object sender, EventArgs e)

    {

    Account a = new Account(50);

    Account b = new Account(50);

    using (TransactionScope ts = new TransactionScope())

    {

    b.Add(60);

    if (a.Subtract(60))

    ts.Complete();

    else

    ts.Dispose();

    }

    MessageBox.Show(a.Money.ToString() + " " + b.Money.ToString());

    }

    I would like to get the result "50 50", but always the result "-10 110".

    Is there any possibility to manage transactions with objects by using System.Transaction namaespace?

    Friday, June 8, 2007 3:30 AM

All replies