Click or drag to resize

ITransactionContext Interface

Represents an ice.NET transaction context. An instance of ITransactionContext is issued when a transaction is started. Once a transaction has been started, it has to be completed by calling Commit() on success or Rollback() on failure.

Namespace:  PDTec.IceNet.Core.Database
Assembly:  PDTec.IceNet.Core (in PDTec.IceNet.Core.dll) Version: 7.2.0.0 (7.2.7583.15464)
Syntax
C#
public interface ITransactionContext : IDisposable

The ITransactionContext type exposes the following members.

Methods
  NameDescription
Public methodCommit
Sucessfully complete the transaction.
Public methodDispose
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
(Inherited from IDisposable.)
Public methodRegisterPostCommitAction
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.
Public methodRegisterPreCommitAction
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.
Public methodRollback
Rollback the database updates performed within the transaction scope.
Top
Remarks

To simplify the usage of transactions, the IDatabaseRepository provides a convenience method ExecuteTransaction(Transactional) that encapsulates the ITransactionContext handling.

Examples

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;
    }
}
Examples

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.

See Also