The requested page is not available for the requested platform. You are viewing the content for Default platform.

IObjectSpace.Refresh() Method

Updates the persistent objects belonging to the current Object Space.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v19.1.dll

Declaration

bool Refresh()
Function Refresh As Boolean

Returns

Type Description
Boolean

true if persistent objects were refreshed; otherwise, false.

Remarks

Use this method to update the current Object Space's persistent objects.

The example below adds a new Contact object to a List View and refreshes the Object Space to show the new object.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using MainDemo.Module.BusinessObjects;
// ...
public class AddContactController : ObjectViewController<ListView, Contact> {
    public AddContactController() {
        ParametrizedAction addContactAction = new ParametrizedAction(
            this, "AddContact", PredefinedCategory.Edit, typeof(string));
        addContactAction.Execute += AddContactAction_Execute;
    }
    private void AddContactAction_Execute(object sender, ParametrizedActionExecuteEventArgs e) {
        using(IObjectSpace objectSpace = Application.CreateObjectSpace(typeof(Contact))) {
            Contact contact = objectSpace.CreateObject<Contact>();
            contact.FirstName = e.ParameterCurrentValue as string;
            objectSpace.CommitChanges();
        }
        View.ObjectSpace.Refresh();
    }
}

When implementing the IObjectSpace interface in the BaseObjectSpace class's descendant, override a protected virtual BaseObjectSpace.Reload method. It is invoked by the BaseObjectSpace.Refresh method, which does the following: If no objects belonging to the current Object Space have been changed after retrieving them or after the last commit (see IObjectSpace.CommitChanges), the BaseObjectSpace.Refresh method recreates the Object Space's container for in-memory objects by calling the Reload method, re-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 save 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 IObjectSpace.CommitChanges method is invoked. This method saves all the tracked changes made to the Object Space's persistent objects to the database. The Refresh method returns true.

  • No

    The BaseObjectSpace.Reload method is invoked to recreate the Object Space's container for in-memory objects (XPObjectSpace.Session in XPObjectSpace and EFObjectSpace.ObjectContext in EFObjectSpace), and persistent objects are re-retrieved. The BaseObjectSpace.Refresh method returns true.

  • Cancel

    The BaseObjectSpace.Refresh 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 Refresh method is invoked within a List View or in an ASP.NET Web application, a confirmation window is not invoked. However, the ConfirmationResult.No value is set by default, which disposes of all changes and again retrieves objects via a reestablished database connection.

The following events related to the Refresh method are available:

So, to implement a refresh operation, you only have to 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 it's EFObjectSpace.ObjectContext).

See Also