Suppose, you have created a domain model reflecting the Categories and Products tables.
Cascading deletes are disabled by default and are only enabled for references specified as dependent. In order to configure your domain model to support cascading delete, you need to perform few simple steps:
- Locate the parent entity in the Visual Designer (in this example, this is the Category entity) and select the navigational property that will be specified as dependent (in this example, this is the Products property).
- Press F4 to open the Properties pane.
- In Properties pane, set the IsDependent property to True.
In this example the Products property is specified as dependent. When you delete a specific Category object, then all referenced Product objects are deleted, too.
Telerik OpenAccess ORM does not check for other references to the deleted dependent instances. If there are other references to the deleted dependent instances, you will get an exception. For example, consider the following domain model.
The Products property of the Category class is configured as dependent. At the same time, the OrderDetails property of the Product entity is not configured as dependent. If you delete a specific Category object, Telerik OpenAccess ORM will try to delete all related Products. However, if there are OrderDetail objects referencing any of the deleted dependent products, you will get an exception. The correct configuration here is to specify the OrderDetails property as dependent.
Thus, when you delete a Category object, Telerik OpenAccess ORM will delete all related Product objects, and all OrderDetail objects related to the deleted Product.
One additional thing you should know about is that the cascade delete does not work in the "parent->child" direction only. You could configure your domain model so that the cascade delete is available in the opposite direction, too. For example, if you make the Category property of the Product entity dependent, then you will achieve the following result: when you delete a child entity (e.g. Product), the corresponding parent entity (e.g. Category) will be deleted too.