Skip to main content

IObjectSpace.Rollback(Boolean) Method

Cancels the changes made to the persistent objects belonging to the current Object Space.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v25.2.dll

NuGet Package: DevExpress.ExpressApp

Declaration

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 to the current Object Space’s persistent objects. For example, the built-in Cancel Action uses this method.

When you implement the IObjectSpace interface in a descendant of the BaseObjectSpace class, you override the protected virtual BaseObjectSpace.Reload method. The BaseObjectSpace.Rollback method calls Reload.

This method checks if no objects in the current object space change after retrieval or after the last commit (see IObjectSpace.CommitChanges). When there are no changes, BaseObjectSpace.Rollback recreates the container for in-memory objects by calling Reload, retrieves the objects, and returns true.

If at least one object changes, the IObjectSpace.ConfirmationRequired event occurs. Handle this event to show a confirmation window and ask whether to cancel changes. Use the XafApplication.AskConfirmation method to display the confirmation dialog. The method returns a ConfirmationResult enumeration value based on the user’s choice. Your next action depends on this result.

  • Yes

    The BaseObjectSpace.Reload method recreates the Object Space’s container for in-memory objects. In XPObjectSpace, it uses XPObjectSpace.Session. In EFCoreObjectSpace, it uses EFCoreObjectSpace.DbContext. Then, the object retrieves persistent objects from the database. 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 WinModificationsController handles the IObjectSpace.ConfirmationRequired event. This controller activates only for Detail Views in Windows Forms applications. The controller shows a confirmation window as described above. The system does not show a confirmation window when you invoke the Rollback method in a List View. However, it sets the ConfirmationResult.Yes value by default. This action rolls back all changes and retrieves objects using a new Session.

The following events related to the Rollback method are available:

To implement a rollback operation, override the BaseObjectSpace.Reload method. In this method, recreate the container for in-memory objects. In XPO, use the XPObjectSpace.Session. In Entity Framework Core, use the EFCoreObjectSpace.DbContext.

The Rollback method includes an optional parameter, askConfirmation = true. If you call the Rollback method without parameters, the method displays the following dialog:

RefreshAskConfirmationq

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

See Also