开发者

NHibernate cascade and inverse

I have three mappings as follows:

public MainChapterMap()
{
    // other properties

    HasMany(x => x.ClientSpecific).KeyColumn("MainChapterId");
}

public MainChapterClientMap()
{
    // other properties

    References(x => x.MainChapter).Column("MainChapterId");
    HasMany(x => x.Details).KeyColumn("MainChapterClientId");
}

public MainChapterClientDetailMap()
{
    // other properties

    References(x => x.MainChapterClient).Column("MainChapterClientId");
}

MainChapter has many client-specific chapters. The client-specific chapters (MainChapterClient) has many translations (MainChapterClientDetail)

The dele rules should be as follow:

  1. When deleting a MainChapter
  2. When deleting a MainChapterClient
    • Do NOT delete the MainChapter row
    • Delete the MainChapterClientDetail row(s)
  3. When deleting a MainChapterClientDetail
    • Do NOT delete the MainChapter row
    • Do NOT delete the MainChapterClientDetail row(s)

But I no matter what I end up getting this error:

deleted object would be re-saved by cascade (remove deleted object from associations)[Entities.MainChapterClient#39]

I'm not sure how to set up my cascades anymore. Any help are more than welcomed!


You need to remove the reference from both sides :

MainChapterClient.Details.Remove(instance);
instance.MainChapterClient = null;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜