IObjectSpace.Refresh() Method
Updates the persistent objects belonging to the current Object Space.
Namespace: DevExpress.ExpressApp
Assembly: DevExpress.ExpressApp.v25.2.dll
NuGet Package: DevExpress.ExpressApp
Declaration
Returns
| Type | Description |
|---|---|
| Boolean |
|
Remarks
Use this method to update the current Object Space‘s persistent objects.
The following code snippet 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 you implement the IObjectSpace interface in a class that descends from BaseObjectSpace, override the protected virtual BaseObjectSpace.Reload method. The BaseObjectSpace.Refresh method calls Reload.
BaseObjectSpace.Refresh works as follows:
If no objects in the current Object Space have changed after you retrieve them or after the last commit (see IObjectSpace.CommitChanges), BaseObjectSpace.Refresh recreates the in-memory object container. It calls the Reload method, retrieves the objects again, and returns true.
If at least one object has changed, the IObjectSpace.ConfirmationRequired event occurs. Handle this event to display a confirmation window that asks whether to save changes. Use the XafApplication.AskConfirmation method. This method returns a ConfirmationResult enumeration value that matches the end user’s choice. The next actions depend on this choice.
Yes
You call the IObjectSpace.CommitChanges method. This method saves all tracked changes in the Object Space’s persistent objects to the database. The
Refreshmethod returnstrue.No
The
BaseObjectSpace.Reloadmethod recreates the Object Space’s container for in-memory objects. InXPObjectSpace, it uses XPObjectSpace.Session. InEFCoreObjectSpace, it uses EFCoreObjectSpace.DbContext. The method re-retrieves persistent objects. The BaseObjectSpace.Refresh method returns true.Cancel
The
BaseObjectSpace.Refreshmethod does nothing and returnsfalse.
The WinModificationsController handles the IObjectSpace.ConfirmationRequired event. This Controller only activates for Detail Views in Windows Forms applications. The handler shows a confirmation window as described above. The application does not show a confirmation window when you call the Refresh method in a List View. By default, the system sets the ConfirmationResult.No value. This value discards all changes and retrieves objects again through a new database connection.
The following events related to the Refresh method are available:
-
Raised before the refresh to prevent it.
-
Raised before the refresh to force a custom refresh operation instead of the default one.
To implement a refresh operation, override the BaseObjectSpace.Reload method. In this method, recreate the Object Space’s container for in-memory objects. In XPO, use XPObjectSpace.Session. In Entity Framework Core, use EFCoreObjectSpace.DbContext.