Reputation: 638
I have A, B and C
B is a child of A
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).
Upvotes: 0
Views: 40
Reputation: 49261
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.
Upvotes: 1