Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

IObjectSpace.CustomDeleteObjects Event

Occurs to replace the default process of deleting persistent objects with a custom one.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v21.1.dll

NuGet Package: DevExpress.ExpressApp

Declaration

event EventHandler<CustomDeleteObjectsEventArgs> CustomDeleteObjects

Event Data

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

Remarks

The IObjectSpace.Delete method raises the CustomDeleteObjects event. Handle this event to implement a custom process for deleting persistent objects. Use the handler’s CustomDeleteObjectsEventArgs.Objects parameter to get the objects to be deleted. Set the handler’s CompletedEventArgs.Handled parameter to true to indicate that the delete operation has already been performed.

The following example demonstrates how to handle this event. The Controller below specifies the IsDeleted property of CustomDeleteObjectsEventArgs.Objects instead of removing them.

using System;
using DevExpress.ExpressApp;
// ...
namespace MySolution.Module.Controllers {
    public class CustomDeleteObjectController : ObjectViewController<DetailView, Employee> {
        protected override void OnActivated() {
            base.OnActivated();
            ObjectSpace.CustomDeleteObjects += new EventHandler<CustomDeleteObjectsEventArgs>(ObjectSpace_CustomDeleteObjects);
        }
        private void ObjectSpace_CustomDeleteObjects(object sender, CustomDeleteObjectsEventArgs e) {
            foreach (object deletingObject in e.Objects) {
                Employee employee = ObjectSpace.GetObject(deletingObject) as Employee;
                employee.IsDeleted = true;
            }
            e.Handled = true;
        }
        protected override void OnDeactivated() {
            ObjectSpace.CustomDeleteObjects -= new EventHandler<CustomDeleteObjectsEventArgs>(ObjectSpace_CustomDeleteObjects);
            base.OnDeactivated();
        }
    }
}

Note that the example above is EF-specific. XPO-based applications support the same functionality out of the box, but you can handle this event for other scenarios.

If you implement the IObjectSpace interface in the BaseObjectSpace class’ descendant, you should override the BaseObjectSpace.DeleteCore method which is called by the BaseObjectSpace.Delete method. In this instance, you won’t have to raise the CustomDeleteObjects event, since it is raised by the BaseObjectSpace.Delete method. For details, refer to the IObjectSpace.Delete method description.

See Also