NHibernate 级联和逆

发布于 2024-09-17 01:21:58 字数 1264 浏览 5 评论 0原文

我有如下三个映射:

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 有许多特定于客户端的章节。客户端特定章节 (MainChapterClient) 有多种翻译 (MainChapterClientDetail)

删除规则应如下:

  1. 删除 MainChapter
    • 删除 MainChapterClient
    • 删除 MainChapterClientDetail
  2. 删除 MainChapterClient
    • 请勿删除 MainChapter
    • 删除 MainChapterClientDetail
  3. 删除 MainChapterClientDetail
    • 请勿删除 MainChapter
    • 请勿删除 MainChapterClientDetail

但我无论如何最终都会收到此错误:

删除的对象将被重新保存 级联(从中删除已删除的对象 关联)[Entities.MainChapterClient#39]

我不知道如何设置我的级联了。非常欢迎任何帮助!

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
    • Delete the MainChapterClient row
    • Delete the MainChapterClientDetail row(s)
  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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘寄 2024-09-24 01:21:58

您需要从两侧删除引用:

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

You need to remove the reference from both sides :

MainChapterClient.Details.Remove(instance);
instance.MainChapterClient = null;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文