3

Searched high and low for an answer but can't make this work with all the examples I've tried.

I have a certain bi directional parent child relationship.

Parent ("Case") holds a collection of children ("CaseNotes") and is mapped as follows:

HasMany<CaseNote>(c => c.Notes).KeyColumn("casesid").Inverse().Cascade.AllDeleteOrphan()

Children reference parent:

References<Case>(c => c.ParentCase,"casesid").Cascade.All();

On Add, the item is added to collection but is not persisted to the DB until explicitly saved (session.Flush() being called)

On delete, the following steps are taken:

Case.Notes.Remove(item.CaseNote); //removes from the Notes collection in parent
item.CaseNote.ParentCase = null; //sets child reference to the parent to null

The expected behavior, is that the AllDeleteOrphan() will smartly remove the null-set children through a delete statement. All works fine except for one awkward scenario - when Add and Delete are called sequentially without the item being persisted - it appears the AllDeleteOrphan() does not trigger and the child foreign key id is simply set to null (causes a contraint violation, but I do not want dangling children in the database anyway).

Has anyone seen this issue before? Any ideas for potential workaround of the issue?

Any help is much appreciated - been tackling this for a while with no luck so far...

Igor Minin
  • 31
  • 1

0 Answers0