Click or drag to resize

IDatabaseRepositoryExecuteTransaction Method (IsolationLevel, Transactional)

Executes a code block as a transaction with a specific isolation level. If a transaction is already active, the code is executed within the scope of this transaction. In this case the isolationLevel argument is ignored.

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#
void ExecuteTransaction(
	IsolationLevel isolationLevel,
	Transactional dTransactional
)

Parameters

isolationLevel
Type: System.DataIsolationLevel
The isolation level.
dTransactional
Type: PDTec.IceNet.Core.DatabaseTransactional
The code to be executed as a 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