NHibernate: deleted object would be re-saved by cascade. Replace object and remove old one

前端 未结 1 1731
一个人的身影
一个人的身影 2021-01-05 23:36

I\'m trying to replace at TimeBlock object on a ProgramItem and then delete the old TimeBlock object. It\'s the delete part that gives me problems. I have some \'relative\'

相关标签:
1条回答
  • 2021-01-06 00:14

    I tried explain what is happening in detail here

    • NHibernate Deleted object would be re-saved by cascade
    • Delete an item from many-to-many relationship

    I would say, that the point is here: the ProgramItem is referenced by some other collection. And that collection was also loaded into the session.

    The best place where to start is - wherever is ProgramItem used (collection item, reference) change the mapping to Cascade.None(). Then try to execute your deletion code. That will work... surely, becuase now cascading in place... no way how to trigger that exception.

    Next - start cascading by pieces. Be sure you know what is allowed, and then you will know which reference, collection is re-saving your object.

    My own experience/approach is - if you delete the item from one place, explicitly delete it from others as well, if there is cascade. It could be challenging, but...

    0 讨论(0)
提交回复
热议问题