NHibernate级联删除

发布于 2024-09-07 01:46:58 字数 663 浏览 1 评论 0原文

我在从 A 到 B 的数据模型中具有一对多关系。但是在我的域 API 中,我不会在 A 上公开“B”(因为我们永远不会从 A 导航到 B),但有来自的引用B到A。现在我希望能够在删除A时删除所有“B”。是否可以?现在 NH 首先尝试将 FK 设置为 null,这是我不想要的,并且不能,因为列不可为空。

A = 供应商类型

B = 基础产品共同保险

   public BaseProductCoInsuranceMap()
        {
            Table("BaseProductCoInsurance");

            Id(x => x.Id, "BaseProductCoInsuranceId");

            Map(x => x.CoInsurancePercent).Column("CoInsrPrcnt");

            References(x => x.BaseProduct, "BaseProductId");
            References(x => x.PolicySupplierType, "PlcySupplierTypeID");
            References(x => x.InsuredType, "InsuredTypeCode");
        }

I have a one-to-many relationship in data model from A to B. But in my domain API I do not expose "B"s on A (since we will never navigate from from A to B), but have a reference from B to A. Now I want to be able to delete all "B"s when A is deleted. Is it possible? Right now NH is trying first to set FK to null, which I don't want, and cannot since column is not nullable.

A = SupplierType

B = BaseProductCoInsurance

   public BaseProductCoInsuranceMap()
        {
            Table("BaseProductCoInsurance");

            Id(x => x.Id, "BaseProductCoInsuranceId");

            Map(x => x.CoInsurancePercent).Column("CoInsrPrcnt");

            References(x => x.BaseProduct, "BaseProductId");
            References(x => x.PolicySupplierType, "PlcySupplierTypeID");
            References(x => x.InsuredType, "InsuredTypeCode");
        }

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

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

发布评论

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

评论(1

轻许诺言 2024-09-14 01:46:58

如果您需要能够级联删除,那么您需要让 NHibernate 了解这种关系。也就是说,您不需要让其他人可以接触到这种关系。您当然可以拥有只有 NH 知道的私人收藏。

如果您将关系设置为延迟加载,您甚至不会看到性能受到影响。

另一个需要考虑的选择是修改您的删除方法以同时删除其他实体。

If you need to be able to cascade delete then you need to let NHibernate know about the relationship. That said you don't need to make the relationship accessible to others. You could of course have a private collection that only NH knows about.

If you make the relationship lazy loaded you shouldn't even see a performance hit from this.

Another option to consider is to just modify your delete method to also delete the other entity.

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