I have the following database scheme:
Code:
______________ __________ ______________
| | | | | |
| ParentOne | | Child | | ParentTwo |
|______________| |__________| |______________|
| | | | | |
| *ParentOneId | <--> | *ChildId | <--> | *ParentTwoId |
| Name | | Name | | Name |
| ChildId | |__________| | ChildId |
|______________| |______________|
That is, a Child can belong to one or more ParentOnes and/or ParentTwos. If there are no references left from ParentOne or ParentTwo to a Child, it should be deleted.
Anyone have any ideas on how to accomplish this?
---
In a first attempt, I have:
- set cascade to all-delete-orphan
- implemented ILifecycle.OnDelete() in the Child class where I veto if there are still references left to the child
I can't seem to get this working though. Besides, I don't like the ILifecycle stuff as it brings NHibernate into my domain objects.