Thank you for contacting us.
Generally, unless your model has been configured to support Cascade Delete
, you will not be able to delete a database entry which has child entries related to it. So if you attempt to delete an employee that has entries in its related child tables, you will receive a DataStoreException
when calling the SaveChanges()
method of the context. It is possible to use this exception to handle scenarios where an entry that should be deleted can have child records.
In case you wish to prevent the attempt of deleting an entry with child records from the start, you will indeed need to check if such records exist. You can do this using the Navigation Properties
of the persistent class
mapped to the Employee table. For example if the Employee table has a child table Account, in your model the Employee persistent class will generally have a property Account which is a reference to the related child object. You can check whether the property is null and only then delete the employee. The following code snippet is an example:
We recommend you consider which would better suit your specific scenario.
I hope this helps. Should you have additional questions, feel free to post in our forums again.
OpenAccess ORM is now Telerik Data Access
. For more information on the new names, please, check out the Telerik Product Map