Rolls the current transaction back.
Syntax
| Visual Basic (Declaration) | |
|---|
Public Sub Rollback() |
| Visual Basic (Usage) | Copy Code |
|---|
Dim instance As ObjectContext
instance.Rollback()
|
| C# | |
|---|
public void Rollback() |
| Managed Extensions for C++ | |
|---|
public: void Rollback(); |
| C++/CLI | |
|---|
public:
void Rollback(); |
Exceptions
| Exception | Description |
| Exception | No transaction active. |
Example
The following example shows how to use transaction management.
| C# | Copy Code |
|---|
// Creates a new ObjectContext that uses an MsSql Server as storage. ObjectContext context = new ObjectContext(new MsSqlStorage("sa", "", "localhost", "application")); // ... Other code. // Get an ObjectSet containing all user matching the name. // The result is sorted by Name. ObjectSet<User> objectSet = context.GetObjectSet<User> ("Name like {0} SortBy Name Asc", "%mith%"); // Change all names of the user objects. foreach(User user in objectSet) { user.Name = "new Name"; } // Starts a new Transaction. context.StartTransaction(); try { // Deletes the user object from the storage. context.PersistChanges(objectSet); // Commit the changes to the storage. context.Commit(); } catch (Exception ex) { // Rolls the changes back. context.Rollback(); Console.WriteLine("Error: " + ex.Message"); } |
Remarks
Requirements
Platforms: Windows 2000, Windows XP family, Windows Server 2003 family, Windows Vista family
See Also