我正在使用 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.
发布评论
评论(1)
我对您的应用程序、性能要求和您所做的测量了解不够。但为了简单起见,不要在 FK 列中人为地创建 0 值。您所做的测量可能不再是相对的,或者这可能从一开始就不是瓶颈。也许有一种方法可以通过在 FK 列上放置索引来提高左连接性能。
在 NHibernate 中进行一对一映射时需要了解的是,可空关联的延迟加载是 这个答案以获取选项。
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.