Skip to main content
.NET 6.0+

IObjectSpace.Delete(Object) Method

Marks the specified persistent object and its aggregated objects as deleted from a persistent storage.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v24.1.dll

NuGet Package: DevExpress.ExpressApp

Declaration

void Delete(
    object obj
)

Parameters

Name Type Description
obj Object

An object which is the persistent object to be deleted.

Remarks

Use this method to delete the object specified as the parameter from the database. Note, that the object is not deleted immediately. It is only marked as an object to be deleted during the next call of the IObjectSpace.CommitChanges method.

In the BaseObjectSpace class’s descendant, the Delete method is implemented. In this method, the IObjectSpace.CustomDeleteObjects event is raised, a protected virtual BaseObjectSpace.DeleteCore method is invoked and then the current Object Space is set as modified. Override the BaseObjectSpace.DeleteCore method to delete the specified object using the container for in-memory objects (for example, XPObjectSpace.Session in the case of an XPObjectSpace or EFCoreObjectSpace.DbContext in the case of an EFCoreObjectSpace).

After this method call, the Object Space’s IObjectSpace.IsModified property is set to true.

The following Controller contains the Action that deletes completed tasks:

File: MySolution.Module\Controllers\TaskViewController.cs(.vb).

using DevExpress.ExpressApp;
using DevExpress.Persistent.BaseImpl;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.Data.Filtering;
using DevExpress.Persistent.Base.General;
using System.Collections.Generic;
// ...
public class TaskViewController : ObjectViewController<ListView, Task> {
    public TaskViewController() {
        SimpleAction deleteCompletedTasksAction = 
            new SimpleAction(this, "Delete completed tasks", PredefinedCategory.Edit);
        deleteCompletedTasksAction.Execute += DeleteCompletedTasksAction_Execute;
    }
    private void DeleteCompletedTasksAction_Execute(object sender, SimpleActionExecuteEventArgs e) {
        CriteriaOperator completedTasksCriteria = 
            CriteriaOperator.FromLambda<Task>(t => t.Status == TaskStatus.Completed);
        IList<Task> completedTasks = ObjectSpace.GetObjects<Task>(completedTasksCriteria);
        ObjectSpace.Delete(completedTasks);
        ObjectSpace.CommitChanges();
    }
}
See Also