Transactions

The JoobContext class provides the BeginTransaction method, which returns a transaction object. All JADE actions required to be in transaction state (that is, create, update, or delete actions) must be within the scope of the transaction object returned by the BeginTransaction method. The transaction object provides the methods Commit and Rollback, to commit or abort the transaction, respectively.

The following example shows a method that uses a transaction to delete a persistent Agent object.

void DeleteClient(Client client)
{
    JoobContext context = JoobContext.CurrentContext;
    using (System.Data.IDbTransaction tx = context.BeginTransaction())
    {
        client.Delete();
        tx.Commit();
    }
}

If the statement that commits the transaction is omitted, the transaction is rolled back when the transaction object is disposed of, at the end of the using block.