IDatabaseRepositoryTransactionContext Property |
Namespace: PDTec.IceNet.Core.Database
ITransactionContext TransactionContext { get; }
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.