Skip to main content
.NET Framework 4.6.2+

IObjectSpace.GetObjectsToDelete(Boolean) Method

Returns a collection of persistent objects that will be deleted when the current transaction is committed, including objects that will be deleted in the parent transaction(s), optionally.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v24.2.dll

NuGet Package: DevExpress.ExpressApp

Declaration

ICollection GetObjectsToDelete(
    bool includeParent
)

Parameters

Name Type Description
includeParent Boolean

true, to include persistent objects that will be deleted in the parent transaction(s); otherwise, false.

Returns

Type Description
ICollection

The collection of persistent objects that will be deleted when the current transaction is committed.

Remarks

When an object is deleted, it’s not deleted from the database immediately. It’s marked as an object to be deleted and removed from the database the next time the IObjectSpace.CommitChanges method is called.

The GetObjectsToDelete method is intended to provide a collection of objects that are marked as deleted in the current transaction.

The code below demonstrates how you can use the GetObjectsToDelete method in your application:

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Blazor;
using YourSolutionName.Module.BusinessObjects;
using System.ComponentModel;

namespace YourSolutionName.Module.Controllers;

public class HandleCommitController :ObjectViewController<DetailView, Contact> {
    protected override void OnActivated() {
        base.OnActivated();
        View.ObjectSpace.Committing += ObjectSpace_Committing;
    }

    private void ObjectSpace_Committing(object sender, CancelEventArgs e) {
        var os = (IObjectSpace)sender;
        var objectsToDelete = os.GetObjectsToDelete(includeParent: true);
        foreach(var item in objectsToDelete) {
            Contact deletedContact = item as Contact;
            if(deletedContact != null && deletedContact.FirstName == "NOT FOR DELETE") {
                e.Cancel = true;
                break;
            }
        }
    }

    protected override void OnDeactivated() {
        View.ObjectSpace.Committing -= ObjectSpace_Committing;
    }
}

In XPO applications with Deferred Deletion enabled, the GetObjectsToDelete method returns an empty collection. In such scenarios, use the GetObjectsToSave(Boolean) method instead.

See Also