Skip to main content
.NET 8.0+

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

IObjectSpace.Delete(IList) Method

Deletes the specified persistent objects and their aggregated objects from the database.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v24.2.dll

NuGet Package: DevExpress.ExpressApp

#Declaration

void Delete(
    IList objects
)

#Parameters

Name Type Description
objects IList

A collection of persistent objects to be deleted from the database.

#Remarks

Use this method to delete the objects passed as the parameter from the database. Note, that the objects are not deleted immediately. They are only marked as objects to be deleted during the next call of the IObjectSpace.CommitChanges method.

In the BaseObjectSpace 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. So, you should only override the BaseObjectSpace.DeleteCore method, to delete the specified objects 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.

Use the following code in a controller to delete all objects from the List View collection:

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;

public class MyViewController : ObjectViewController<ListView, MyClass> {
    public MyViewController() {
        var action = new SimpleAction(this, "Delete all objects", DevExpress.Persistent.Base.PredefinedCategory.Edit);
        action.Execute += Action_Execute;
    }

    private void Action_Execute(object sender, SimpleActionExecuteEventArgs e) {
        this.ObjectSpace.Delete(View.CollectionSource.List);
        this.ObjectSpace.CommitChanges();
    }
} 
See Also