Skip to main content
.NET 8.0+

IObjectSpace.CustomDeleteObjects Event

The IObjectSpace.Delete method raises the CustomDeleteObjects event. Handle this event to replace the default persistent object deletion logic with custom logic.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v24.2.dll

NuGet Package: DevExpress.ExpressApp

Declaration

event EventHandler<CustomDeleteObjectsEventArgs> CustomDeleteObjects

Event Data

The CustomDeleteObjects event's data class is DevExpress.ExpressApp.CustomDeleteObjectsEventArgs.

Remarks

Use the handler’s CustomDeleteObjectsEventArgs.Objects parameter to obtain the objects to be deleted. Set the handler’s CompletedEventArgs.Handled parameter to true to indicate the delete operation is completed.

The Controller below specifies the IsMarkedAsDeleted property of CustomDeleteObjectsEventArgs.Objects instead of removing them:

File: MySolution.Module\Controllers\CustomDeleteObjectController.cs.

using DevExpress.ExpressApp;
// ...
public class CustomDeleteObjectController : ObjectViewController<DetailView, Employee> {
    protected override void OnActivated() {
        base.OnActivated();
        ObjectSpace.CustomDeleteObjects += ObjectSpace_CustomDeleteObjects;
    }
    private void ObjectSpace_CustomDeleteObjects(object sender, CustomDeleteObjectsEventArgs e) {
        foreach (object deletingObject in e.Objects) {
            Employee employee = ObjectSpace.GetObject(deletingObject) as Employee;
            // IsMarkedAsDeleted is a custom Employee's property
            employee.IsMarkedAsDeleted = true;
        }
        e.Handled = true;
    }
    protected override void OnDeactivated() {
        ObjectSpace.CustomDeleteObjects -= ObjectSpace_CustomDeleteObjects;
        base.OnDeactivated();
    }
}

Note

This event is raised only when you use IObjectSpace methods to delete objects.

EF Core and XPO have similar functionality out of the box:

If you implement the IObjectSpace interface in the BaseObjectSpace class descendant, you can override the BaseObjectSpace.DeleteCore method instead of handling the CustomDeleteObjects event. The BaseObjectSpace.Delete method calls the BaseObjectSpace.DeleteCore method and raises the CustomDeleteObjects event. This means you can implement custom deletion logic in any of these places. For more information, refer to the IObjectSpace.Delete method description.

See Also