NHibernate 推荐的外键数据库结构

发布于 2024-11-30 20:11:07 字数 302 浏览 0 评论 0 原文

我正在使用 NH 和 Sql Server 开发一个应用程序。我已经决定了 然后采用自己创建数据库结构的方法 之后与 NH 进行映射。

创建数据库结构时,我喜欢使用外键 保持引用完整性。在有一个人要 一个可为空的表映射,我过去创建了一个 查找表上的虚拟零 ID 行。我这样做的原因 这是因为我发现左连接查询并不像 性能与完全连接一样。

我渴望进步并有兴趣获得一些关于我是否可以的建议 应该用我的新数据库结构再次追求这个目标 意味着让 NH 在选择时全局忽略零 ID。我 怀疑使用 NH 时可能充满危险,也许我 我最好采用数据库的替代路线。任何建议 非常感谢。

I am developing an application with NH and Sql Server. I have decided
to go with the method of creating the database structure myself then
map with NH afterwards.

When creating a database structure I like to use foreign keys to
maintain referential integrity. In the cases where there is a one to
one table mapping which is nullable, I have in the past created a
dummy zero ID row on the lookup table. The reason that I have done
this is because I have seen that left join queries were not as
performant as full joins.

i am keen to improve and interested to get some advice for whether i
should pursue this again with my new database structure which would
mean getting NH to ignore zero ID's globally upon selects somehow. i
suspect this could be fraught with danger when using NH and perhaps i
am better taking an alternative route with the database. any advice
very appreciated thanks.

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

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

发布评论

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

评论(1

浅黛梨妆こ 2024-12-07 20:11:07

我这样做的原因是因为我看到了 left join
查询的性能不如完全连接。

我对您的应用程序、性能要求和您所做的测量了解不够。但为了简单起见,不要在 FK 列中人为地创建 0 值。您所做的测量可能不再是相对的,或者这可能从一开始就不是瓶颈。也许有一种方法可以通过在 FK 列上放置索引来提高左连接性能。

在 NHibernate 中进行一对一映射时需要了解的是,可空关联的延迟加载是 这个答案以获取选项。

The reason that I have done this is because I have seen that left join
queries were not as performant as full joins.

I don't know enough about your application, performance requirements and the measurements that you did. But it might be worth not creating artificial 0 value in FK column just for the simplicity sake. The measurement that you did might no longer be relative or maybe this was not a bottleneck in the first place. Maybe there is a way to improve left join performance by putting index on FK column.

What you need to know when mapping one-to-one in NHibernate is that lazy loading for nullable associations is not supported. Look at this answer for options.

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