Skip to main content
.NET Framework 4.5.2+

Session.Delete(Object) Method

Deletes the specified persistent object and its aggregated objects from persistent storage.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v24.1.dll

NuGet Package: DevExpress.Xpo

Declaration

public void Delete(
    object theObject
)

Parameters

Name Type Description
theObject Object

An object which represents the persistent object to delete.

Remarks

Below is an example of using the Delete method. Here, session is the Session instance.

Person personToDelete = session.GetObjectByKey<Person>(152);
session.Delete(personToDelete);

If a persistent object has the DeferredDeletionAttribute, the Delete method doesn’t actually remove the underlying database record. Instead, it marks the record as deleted and writes a reference to this object for later use by the Session.PurgeDeletedObjects method. You should clear all references to the object to be deleted. Otherwise, the object will not be purged. To persist the deleted state, save the object by calling its XPBaseObject.Save method.

If the DeferredDeletionAttribute isn’t specified, the Delete method removes the underlying database record which corresponds to the persistent object unless there are references to this object.

Note

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.

The following code snippets (auto-collected from DevExpress Examples) contain references to the Delete(Object) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also