Skip to main content
.NET 6.0+

Session.Delete(ICollection) Method

Deletes persistent objects and their aggregated objects from the data store.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v24.1.dll

NuGet Package: DevExpress.Xpo

Declaration

public void Delete(
    ICollection objects
)

Parameters

Name Type Description
objects ICollection

A collection of persistent objects to delete from the data store.

Remarks

If a persistent object has the DeferredDeletionAttribute, the Delete method does not physically delete the underlying database record. It uses a hidden GCRecord field to mark the object as deleted. Clear all references to the object to delete this object when the Session.PurgeDeletedObjects method is called.

If the DeferredDeletionAttribute is not set, the Delete method removes the underlying database record if this operation does not violate foreign key constraints.

How to Delete All Objects in an XPCollection

The following code deletes all objects in an XPCollection and deletes the corresponding database records:

using DevExpress.Xpo;  
using DevExpress.Data.Filtering;  
// ...  
var colDelete = new XPCollection<YourPersistentType>(theSession, new BinaryOperator("YourPropertyName", true)); // Objects for deletion.
theSession.Delete(colDelete); 

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(ICollection) 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