Deferred and Immediate Object Deletion

  • 2 minutes to read

Deferred Object Deletion

If the XPObject or XPCustomObject is used as the base class for persistent objects, deferred deletion is enabled. This means that when you delete an object, XPO does not physically remove the corresponding record from the underlying data store. Instead, it marks the record as deleted. This technique avoids database exceptions when deleting objects that are referenced by other objects.

By default, objects marked as deleted are never retrieved from the object store unless they are referenced directly. A delete operation also deletes all aggregated objects (see AggregatedAttribute).

You can also use the Session.Delete method to delete persistent objects. This method accepts a collection as a parameter and calls the XPBaseObject.Delete method for each object in the collection. The Session.PurgeDeletedObjects method will delete objects marked as deleted, along with all corresponding records from the data store.

Deleted objects can be restored later on, see How to restore deleted object (records).


When an object with Deferred Deletion enabled is deleted, it is removed from associated collections. Associations cannot be recreated automatically when you restore a deleted object. This behavior is by design, because the Deferred Deletion feature is not intended for object restoration, but for overcoming complex foreign index constraints at the database level.

Immediate Object Deletion

If the XPBaseObject is used as the base class for persistent objects, immediate object deletion is enabled. In this instance, records corresponding to deleted objects are physically deleted. Note that you will get an exception when deleting an object that participates in many-to-many relationships, because the hidden intermediate object references your object. This is why all references to the object should be cleared before deletion .


To enable deferred object deletion, apply the DeferredDeletionAttribute.


The functionality described here is demonstrated in the Data Exchange and Manipulation | Deleting Persistent Objects section of the XPO Tutorials demo (C:\Users\Public\Documents\DevExpress Demos 19.2\Components\WinForms\Bin\XpoTutorials.exe).