开发者

NHibernate cascaded delete's other parent

开发者 https://www.devze.com 2023-02-01 07:57 出处:网络
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)

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号