Fluent NHibernate Self Referencing Many To Many

后端 未结 2 903

I have an entity called Books that can have a list of more books called RelatedBooks.

The abbreviated Book entity looks something likes this:

public clas         


        
2条回答
  •  情歌与酒
    2021-02-08 16:35

    Rather than setting the cascade attribute, I think you need to simply empty the RelatedBooks collection before deleting a book.

    book.RelatedBooks.Clear();
    session.Delete(book);
    

    Cascading deletes is not typically done in a many-to-many relationship because it will delete the object at the other end of the relationship, in this case a Book.

提交回复
热议问题