.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

Session.Delete(ICollection) Method

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

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v21.2.dll

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.

The following code deletes all objects in a collection 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.

See Also