Click or drag to resize

IDatabaseRepositoryTransactionContext Property

Gets the current transaction context.

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#
ITransactionContext TransactionContext { get; }

Property Value

Type: ITransactionContext
The current transaction context. null if there is no active transaction.
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