NHibernate cascaded delete's other parent
I have A, B and C
B is a child of A开发者_Go百科
C is a child of B but B is not a parent of C (i.e. does not 'have-a' C - one way relationship)C cascades deletes to B
so if I:
Session.Delete(C);
B will have been deleted, however A still has a reference to it and I get a "will be resaved" exception. Is there anyway around this without removing B from A's collection first? (which isn't a massive problem just adds extra code that I don't see as necessary).
Is there anyway around this without removing B from A's collection first?
No. The instance of B remains in code even after it has been deleted from the database. Delete really means make non-persistent when the session is flushed. If A has the B instance in a collection with cascading turned on, then it will be re-inserted after the delete.
精彩评论