ITransactionContext Interface |
Namespace: PDTec.IceNet.Core.Database
public interface ITransactionContext : IDisposable
The ITransactionContext type exposes the following members.
Name | Description | |
---|---|---|
Commit |
Sucessfully complete the transaction.
| |
Dispose | Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. (Inherited from IDisposable.) | |
RegisterPostCommitAction |
Registers a post commit action. The action is executed by the platform
after the transaction has been successfully completed (commit). The
action itself is not part of the transaction.
| |
RegisterPreCommitAction |
Registers a pre commit action. The action is executed by the platform
before the transaction is completed (commit). The
action itself is part of the transaction.
| |
Rollback |
Rollback the database updates performed within the transaction scope.
|
To simplify the usage of transactions, the IDatabaseRepository provides a convenience method ExecuteTransaction(Transactional) that encapsulates the ITransactionContext handling.
This example shows how to use an ITransactionContext to implement an atomic, exception-safe transaction scope.
using (ITransactionContext pTransaction = Repository.BeginTransaction()) { try { // [do some updates, throw exception on failure]... // Transaction sucessfully completed... pTransaction.Commit(); } catch { // Transaction failed... pTransaction.Rollback(); throw; } }
This example shows how to use the ExecuteTransaction(Transactional) convenience method to implement an atomic, exception-safe transaction scope.
Repository.ExecuteTransaction(delegate() { // [do some updates, throw exception on failure]... });
The commit/rollback handling is done automatically based on wether the ExecuteTransaction(Transactional) scope is exited regularly or with an exception.