当子类具有不可空字段时,每个层次结构表映射?

发布于 2024-09-30 18:46:51 字数 217 浏览 0 评论 0原文

我有一个带有抽象基类和 4-5 个子类的类层次结构。我想使用 NHibernate 的每类层次结构表映射方法将它们映射到单个数据库表,以减少查询生成的联接数量。

然而,这些子类之一具有其他子类所缺乏的非空属性。这意味着每当我尝试保存其他子类型之一的实体时,我都会收到一条 SQL 错误,指出缺少的字段不能为空。

这是否意味着每个层次结构表与我的域模型根本不兼容,或者我还需要做其他事情吗?

I have a class hierarchy with an abstract base class and 4-5 subclasses. I want to use NHibernate's table-per-class-hierarchy mapping method to map these to a single database table to reduce the number of joins my queries generate.

However, one of those subclasses has a not-null property which the other subclasses lack. This means that whenever I try to save an entity of one of those other subtypes, I get a SQL error saying that the missing field cannot be null.

Does this mean that table-per-hierarchy is simply incompatible with my domain model, or is there something else I need to do?

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

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

发布评论

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

评论(1

暖阳 2024-10-07 18:46:51

对于没有该属性的类,您希望该字段包含什么?

由于它可能为 NULL,因此您应该将其设置为可为空,但在模型/业务逻辑中验证它。

What do you expect that field to contain for the classes that don't have that property?

Since it's probably NULL, you should just make it nullable, but validate it in your model/business logic.

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