We recommend using Visual Studio 2017
This documentation is archived and is not being maintained.

ILinkedUndoTransaction Interface

A transaction allows you to group together operations on the UML model store, so that if any of them fails, the whole group is rolled back. After the transaction is committed, the user can undo the whole group with a single undo command.

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

public interface ILinkedUndoTransaction : IDisposable

The ILinkedUndoTransaction type exposes the following members.

Public propertyIdThe name of this transaction set by BeginTransaction().

Public methodAbortUndo all the changes to the model store that have occurred since the transaction was created. Disposing the transaction without committing it has the same effect. Abort will not undo changes to other program variables, or external resources.
Public methodCommitComplete the transaction so that when it is disposed, the operations performed within it will not be undone.
Public methodDisposePerforms application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. (Inherited from IDisposable.)

In a Visual Studio extension, you can to obtain a context from which an ILinkedUndoTransaction can be created as follows:

public ILinkedUndoContext LinkedUndoContext { get; set; }

In a method, you can create a transaction from this context:

using (ILinkedUndoTransaction transaction =
              LinkedUndoContext.BeginTransaction("Swap names"))
    transaction.Commit(); // Always remember Commit()!

An exception that is not caught inside the using block will cause all the UML model changes inside it to be rolled back. Note that this applies only to changes on the UML model, and not to changes that have been made to other variables, external databases, files, and so on.

Transactions can be nested.

For more information, see How to: Link Model Updates using Transactions.