EasyObjects.NET Programmers Reference

TransactionManager Class

TransactionManager is used to seemlessly enroll an EasyObject into a transaction. TransactionManager uses ADO.NET transactions and therefore is not a distributed transaction as you would get with COM+. You only have to use TransactionManager if two or more EasyObjects need to be saved as a transaction. The EasyObject.Save method is already protected by a transaction.

For a list of all members of this type, see TransactionManager Members.

System.Object
   NCI.EasyObjects.TransactionManager

public class TransactionManager

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

Transaction Rules:

Transactions are stored in the Thread Local Storage or TLS. This way the API isn't intrusive, ie, forcing you to pass a Connection around everywhere. There is one thing to remember, once you call RollbackTransaction you will be unable to commit anything on that thread until you call ThreadTransactionMgrReset(). In an ASP.NET application each page is handled by a thread that is pulled from a thread pool. Thus, you need to clear out the TLS (thread local storage) before your page begins execution. The best way to do this is to create a base page that inhertis from System.Web.UI.Page and clears the state like this:

Example

VB.NET

Dim tx As TransactionManager = TransactionManager.ThreadTransactionMgr()

Try
    tx.BeginTransaction()
    emps.Save()
    prds.Save()
    tx.CommitTransaction()
Catch ex As Exception
    tx.RollbackTransaction()
    tx.ThreadTransactionMgrReset()
End Try
C#
TransactionManager tx = TransactionManager.ThreadTransactionMgr();

try
{
    tx.BeginTransaction();
    emps.Save();
    prds.Save();
    tx.CommitTransaction();
}
catch(Exception ex)
{
    tx.RollbackTransaction();
    tx.ThreadTransactionMgrReset();
}

Requirements

Namespace: NCI.EasyObjects

Assembly: NCI.EasyObjects (in NCI.EasyObjects.dll)

See Also

TransactionManager Members | NCI.EasyObjects Namespace | Save