如何在 Fluent Nhibernate 中映射和使用联结表?
我有一个带有 2 个表和一个连接表的经典场景。 比方说,位置、价格和LocationXPrices。
LocationXPrices 仅包含位置和价格的 id,以便我们知道它们之间的关系。
我们得出的最佳方法是这样的: - 将多个位置映射到价格 - 将价格映射到位置 - 没有特定的映射,也没有 LocationsXPrices 的 .NET 对象。
读取位置时将创建交汇点。 插入将与位置一起完成。
这是处理这种情况的最佳实践吗? 谁能提供更好的解决方案? 我觉得这不太自然。
谢谢你, 摩苏。
I have the classic scenario with 2 tables and a junction table.
Let's say, Locations, Prices and LocationXPrices.
LocationXPrices contains only the id's of Locations and Prices so that we know how they relate.
The best approach we came to is like this:
- map Locations as many to many to Prices
- map Prices as many to many to Locations
- no specific mapping and no .NET object for LocationsXPrices.
The junction will be created when Locations will be read.
Insert will be done together with Location.
Is this the best practice to work with this scenario ?
Can anyone provide a better solution ?
It doesn't' feel that natural to me.
Thank you,
Mosu.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是最佳实践,其中您的联结表代表像这样的纯弱实体,没有其他信息。连接表只是在 RDBMS 中对此类情况进行建模的必要工件; NHibernate 允许您完全隐藏它,这样您就可以使用真正的多对多关系,而不是 RDBMS 强制的多对多关系。
Yes, this is best practice where your junction table represents a pure weak entity like this, with no other information. The junction table is merely a necessary artifact of modelling this sort of situation in an RDBMS; NHibernate lets you hide it totally so you can work with a genuine many-many relationship rather than the RDBMS's enforced many-one-many.