IObjectSpace.Rollback(Boolean) Method
Cancels the changes made to the persistent objects belonging to the current Object Space.
Namespace: DevExpress.ExpressApp
Assembly: DevExpress.ExpressApp.v24.1.dll
NuGet Package: DevExpress.ExpressApp
Declaration
Optional Parameters
Name | Type | Default | Description |
---|---|---|---|
askConfirmation | Boolean | True | true, if the confirmation dialog is required, otherwise, false. |
Returns
Type | Description |
---|---|
Boolean | true, if changes made to persistent objects were canceled; otherwise, false. |
Remarks
Use this method to cancel the changes made to the current Object Space’s persistent objects. For example, this method is used by the built-in Cancel Action.
When implementing the IObjectSpace interface in the BaseObjectSpace class’s descendant, override a protected virtual BaseObjectSpace.Reload method. It is invoked by the BaseObjectSpace.Rollback method, which does the following: If none of the objects belonging to the current object space have been changed after retrieving them or after the last commit (see IObjectSpace.CommitChanges), the BaseObjectSpace.Rollback method recreates the Object Space’s container for in-memory objects by calling the Reload method, retrieves the objects from it and returns true. If at least one object change has been performed, the IObjectSpace.ConfirmationRequired event is raised. Handle this event to show a confirmation window that asks whether to cancel changes. For this purpose, use the XafApplication.AskConfirmation method. This method returns the ConfirmationResult enumeration value that corresponds to an end-user’s choice. Successive actions depend on this choice:
Yes
The BaseObjectSpace.Reload method is invoked to recreate the Object Space’s container for in-memory objects (XPObjectSpace.Session in XPObjectSpace and EFCoreObjectSpace.DbContext in EFCoreObjectSpace). Then, persistent objects are retrieved from the database via this object and the BaseObjectSpace.Rollback method returns true.
No
The BaseObjectSpace.Rollback method does nothing and returns false.
Cancel
The *Rollback* method does nothing and returns false.
The IObjectSpace.ConfirmationRequired event is handled only by the WinModificationsController, which is activated for Detail Views in Windows Forms applications. The Controller’s handler invokes a confirmation window as described above. When the Rollback method is invoked within a List View or in an ASP.NET Web Forms application, a confirmation window is not invoked. However, the ConfirmationResult.Yes value is set by default, which leads to rolling back all changes and retrieving objects via a newly assigned Session.
The following events related to the Rollback method are available:
-
Raised before the rollback to prevent it.
-
Raised before the rollback to perform a custom rollback instead of the default one.
So, to implement a rolling back operation, you have to only override the BaseObjectSpace.Reload method. In this method, recreate the Object Space’s container for in-memory objects (in XPO it’s a XPObjectSpace.Session. In the Entity Framework Core it’s EFCoreObjectSpace.DbContext).
The Rollback method has the askConfirmation = true optional parameter. If you call the Rollback method with no parameters, the method’s execution prompts the following dialog:
To roll back an Object Space without a confirmation dialog, explicitly pass false as the askConfirmation parameter.