Skip to main content
.NET 6.0+

BaseObjectSpace.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

public bool Rollback(
    bool askConfirmation = true
)

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 ModificationsController.CancelAction Action.

If none of the objects belonging to the current object space have been changed after retrieving them or after the last commit (see BaseObjectSpace.CommitChanges), the Rollback method recreates the object that the Object Space uses for interacting with data in the form of persistent objects. Thus, the persistent objects retrieved by the current Object Space are refreshed. The Rollback method returns true if rolling back was performed successfully.

If at least one object change has been performed, the BaseObjectSpace.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 object that the Object Space uses for interacting with data in the form of persistent objects is recreated, and persistent objects are retrieved from the database via this object. The Rollback method returns true.

  • No

    The Rollback method does nothing and returns false.

  • Cancel

    The Rollback method does nothing and returns false.

The BaseObjectSpace.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.

The following events related to the Rollback method are available:

  • BaseObjectSpace.RollingBack

    Handle this event to prevent a rollback performed by the Rollback method. For this purpose, set the handler’s CancelEventArgs.Cancel parameter to true.

  • BaseObjectSpace.CustomRollBack

    Handle this event to perform a custom rollback instead of a default one. Set the handler’s CompletedEventArgs.Handled parameter to true, to indicate that the rolling back operation has already been performed. Set the handler’s CompletedEventArgs.IsCompleted parameter to the value which will be returned by the Rollback method.

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: RefreshAskConfirmation

To roll back an Object Space without a confirmation dialog, explicitly pass false as the askConfirmation parameter.

Implements

See Also