All docs
V20.2
21.1 (EAP/Beta)
20.2
20.1
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.
.NET Standard 2.0+
.NET Framework 4.5.2+
.NET Standard 2.0+

Session.DeleteAsync(Object, CancellationToken) Method

Asynchronously deletes the specified persistent object and its aggregated objects from persistent storage.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v20.2.dll

Declaration

public Task DeleteAsync(
    object theObject,
    CancellationToken cancellationToken = default(CancellationToken)
)

Parameters

Name Type Description
theObject Object

An object which represents the persistent object to delete.

Optional Parameters

Name Type Default Description
cancellationToken CancellationToken

null

A CancellationToken object that delivers a cancellation notice to the running operation.

Returns

Type Description
Task

A Task that deletes the specified persistent object and its aggregated objects from persistent storage.

Remarks

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

using System.Threading.Tasks;
// ...
private async Task DeleteOrder() {
    await this.UnitOfWork.DeleteAsync(this.CurrentOrder);
}

If a persistent object has the DeferredDeletionAttribute, the DeleteAsync 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 DeleteAsync 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.

See Also