Transaction Class

A transaction makes sure that changes that were made to the store are treated as a group that can be committed or rolled back.

Namespace:  Microsoft.VisualStudio.Modeling
Assembly:  Microsoft.VisualStudio.Modeling.Sdk (in Microsoft.VisualStudio.Modeling.Sdk.dll)

Syntax

'Declaration
Public Class Transaction _
    Inherits MarshalByRefObject _
    Implements IDisposable
'Usage
Dim instance As Transaction
public class Transaction : MarshalByRefObject, 
    IDisposable
public ref class Transaction : public MarshalByRefObject, 
    IDisposable
public class Transaction extends MarshalByRefObject implements IDisposable

Remarks

A transaction enables you to group changes. It also keeps track of the actions that are performed in a transaction so that they can be undone at a later stage.

Changes to the store must be done in a transaction. Changes to the store are made only if the transaction commits. A transaction can have the store accept the changes when the local transaction is committed or when the top-level transaction is committed. Local transactions are nested in a top-level transaction. A nested transaction must commit or roll back before the next top-level transaction can commit or roll back. For more information, see the example for the TransactionDepth property.

A transaction also keeps track of the actions that have occurred. This enables a group of actions to be undone or redone at a later stage with the UndoManager property.

A transaction should be disposed. This can be done by using the Dispose method or by creating the transaction in a Using construct. If the transaction has not been committed when it is disposed, the transaction is automatically rolled back and any changes are canceled.

Examples

The following example shows a transaction that modifies the store. The transaction is committed. If the transaction is rolled back, any changes to the store are canceled. The transaction is disposed automatically at the end of the using block.

using (Transaction txCreateElem =  model.Store.TransactionManager.BeginTransaction("Create named element")
{
  A a = new A(store);
  a.Name = "Fred";
  // Commit the transaction and add the named element to the model
  txCreateElem.Commit();
}

Inheritance Hierarchy

System.Object
  System.MarshalByRefObject
    Microsoft.VisualStudio.Modeling.Transaction

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Transaction Members

Microsoft.VisualStudio.Modeling Namespace