Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
Dependent References / Cascading Delete
Programmer's Guide > OpenAccess ORM Classic (Old API) > Programming With OpenAccess > Mapping > Simple and Reference Fields > Dependent References / Cascading Delete

Glossary Item Box

This documentation article is a legacy resource describing the functionality of the deprecated OpenAccess Classic only. The contemporary documentation of Telerik OpenAccess ORM is available here.

OpenAccess ORM supports dependent references. That is, if the referencing instance is deleted then the dependent, referenced instance is also deleted. This is often called as cascading deletes. This feature must be used with caution as OpenAccess ORM does not check for other references to the deleted referenced instances. If there are other references to the deleted dependent references, at best you will get an exception when you commit the transaction (e.g., if there is a constraint). Or worse, the transaction will succeed and you will get errors when you later attempt to traverse a reference to a deleted instance.

Cascading deletes are disabled by default and are only enabled for references specified as dependent, by adding the [OpenAccess.Depend] attribute to the referenced persistent class.

In the following example, the Address reference in Employee is specified as dependent. So, the referenced Address instance is deleted when Employee instance is deleted:

C# Copy Code
public class Employee
private Address address;
 . . .
VB .NET Copy Code
<OpenAccess.Persistent> _
Public Class Employee
  <OpenAccess.Depend()> _
  Private address As Address
End Class

In case of maps, for dependent referenced value object(s) and referenced key object(s), the dependent and keys-dependent metadata extension entries are added to the App.config file.

OpenAccess ORM also supports cascading deletes for collections (refer to Dependent Collections / Cascading Deletes) and can also automatically delete certain types of orphan (unreferenced) instances (refer to Automatically Deleting Orphans).

The <delete-orphans> extension is a class level extension (See delete-orphans) for one-to-many relationships implemented using an inverse foreign key (for e.g. the Order and OrderLine classes in the One-to-many Mapping section). If <delete-orphans> is true for a child class OrderLine then any instance that ends with a null Order reference (parent) when a transaction is committed is deleted. This is very useful when the child class can have more than one parent class. All the parents must be null before it is deleted.