| West Wind Web Store .NET 2.0 |
Transactions
|
Transactions are easy to use:
busCustomer Customer = WebStoreFactory.GetbusCustomer(); Customer.BeginTransaction(); Customer.Load("1000"); wws_customersRow CustRow = Customer.GetTypedDataRow(); this.lblResult.Text = CustRow.Lastname; CustRow.Lastname = "Updated Name"; Customer.Save(); Customer.New(); CustRow.GetTypedDataRow(); CustRow.Lastname = "Jimmy"; CustRow.Company = "Jimmini"; Customer.Save(); Customer.RollbackTransaction();
In this scenario a business object the Transaction is scope to the single business object and the entire set of commands operates under the single transaction context.
Be aware that although this works well this is not optimal for performance as you are locking any rows affected for the whole duration of the transaction.
Customer.BeginTransaction(); Customer.Load("1000"); Customer.DataRow["LastName"] = "Updated Name"; Customer.Save(); busItem Item = WebStoreFactory.GetbusItem(); Item.New(); Item.DataRow["Sku"] = "NEWITEM"; Item.DataRow["Descript"] = "New Item Description"; Item.Save(); Customer.RollbackTransaction()
the transaction would have no effect, since the transaction is scoped to the Customer object. This is true even if you used the Item object in a method inside of the Customer object. If you want the Item object to participate in the Transaction you have to explicitly assign the transaction to the 'child' object:
IDbTransaction Transaction = Customer.BeginTransaction(); Item.SetTransaction(Transaction);
Now the above code will cause the rollback to rollback both the Customer and LineItem objects.
You have access to the underlying Transaction object via:
wwBusiness.Data.Transaction
You can check this object for null and any of the properties if instantiated.
Last Updated: 12/17/2003 |
Send topic feedback