my application has 2 entities called Event and Transaction. An Event may or may not have a transaction but can only have 1 Transaction. I thought the best way to map this was with a HasOne mapping. So far everything is fine but i want to make sure that when you delete an Event it won’t delete it if has a Transaction.
Normally on a HasMany relationship i would just set an Inverse and change Cascade to None. While Cascade exists, Inverse doesn’t and the event deletes regardless of whether it has a Transaction or not.
I’d appreciate it if someone could show me the correct way of doing this. Thanks
You could always create your own custom delete behaviour using a DeleteEventListener:
This DeleteEventListener would then need to be registered as part of your NHibernate setup configuration. Within the session factory element:
I haven’t tested this particular code but I have similar code in my app so I can help out if you get stuck.