C# .NET TransactionManagers

Top  Previous  Next

The Transaction Manager is accessed from the TransactionManager property of the current database. Once a reference to the Transaction Manager is made, you can use one of the following methods to start or obtain a transaction:

 

StartTransaction – Starts a new transaction by creating a new instance of a Transaction object. Use this method when you need to write to an object multiple times and control how the changes can be rolled back through the use of different nesting levels.
StartOpenCloseTransation – Creates an OpenCloseTransaction object, which behaves similar to a Transaction object, that wraps the Open and Close methods of an object making it easier to close all opened objects instead of having to explicitly close each opened object. Recommended for use in support or utility functions that might be called an unknown number of times, and used when working with most event handlers.

 

So as far as I can see it is easiest to use StartOpenCloseTransation. Used like this:

 

 

using (var tr = db.TransactionManager.StartOpenCloseTransaction())

{

   // Open the block table...

   var blockTable = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);

 

   // So stuff...

 

   // Change things...

 

   // Save the changes...

   tr.Commit();

}