2

I have two entities which have a one-to-one relationship. For the sake of consistency with other similar record types this relationship is maintained in a table with foreign key relationships to the corresponding entities.

House ↔ Resident ↔ Person

A person is associated with other entities which on delete logically cascade all the way to the resident entity. However, when an resident is deleted I need to determine if that delete should be cascaded to the house entity. I have two scenarios where I do not want to cascade the delete:

  • when a house has other residents
  • when the resident entity is being deleted directly not because of a cascade

I have read through the NHibernate Interceptors and Events documentation, but have yet to come up with a mechanism utilizing pre/post event listeners or interceptors which provides the hooks I need.

In an event listener can I determine if a resident entity is being deleted directly or because of a cascade? Stated differently how can I determine the source of deletion in an event listener?

ahsteele
  • 26,243
  • 28
  • 134
  • 248

0 Answers0