A transaction is an indivisible unit of work and it is used to ensure data integrity. Transactions control the concurrent access of data by multiple programs. In the event of a system failure, transactions ensure that after recovery the data is in a consistent state. All operations on a persistent class need to be carried out within a transaction. Transactions are started with Transaction.Begin(), following this you can do whatever operations are needed. A transaction can end in two ways: with a commit or a rollback. Transaction.Commit() attempts to save all the changes to the database, however, if any statement within the transaction fails, the transaction is rolled back, undoing all the effects of the statements in the transaction.
This chapter examines the working of transactions in OpenAccess ORM in detail and it includes the following sections: