Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual Studio SDK
Transaction Class
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Domain-Specific Language Tools Reference
Transaction Class

Updated: November 2007

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)

Visual Basic (Declaration)
Public Class Transaction _
    Inherits MarshalByRefObject _
    Implements IDisposable
Visual Basic (Usage)
Dim instance As Transaction
C#
public class Transaction : MarshalByRefObject, 
    IDisposable
Visual C++
public ref class Transaction : public MarshalByRefObject, 
    IDisposable
JScript
public class Transaction extends MarshalByRefObject implements IDisposable

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.

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();
}
System..::.Object
  System..::.MarshalByRefObject
    Microsoft.VisualStudio.Modeling..::.Transaction
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker