Fluent Nhibernate,如何处理一个有很多而实际上只有一个的情况?

发布于 2024-09-24 10:01:54 字数 473 浏览 1 评论 0原文

目前我有一个表“ComponentAnalysis”和一个表“HistoryOfUse”,我试图在 Fluent NHibernate 中映射它们。

一个成分分析应该只有 1 个使用历史记录,并且一个使用历史记录应该属于 1 个成分分析。这对我来说应该将表设置为一对一映射。但DB的设计者并没有这样设置。

相反,“HistoryOfUse”有一列“ComponentAnalysisID”来指定它属于哪个组件分析。为了符合数据库,我应该有 HistoryOfUse References ComponentAnalysis,并且 ComponentAnalysis 应该有 HasMany HistoryOfUse。

但如果我这样做,那么我需要一个 HistoryOfUse 类型的列表,这看起来相当烦人。有没有一种方法可以在不更改数据库的情况下进行设置,以允许 ComponentAnalysis 具有单个 HistoryOfUse 对象,即使根据数据库结构,它应该具有它们的列表?

Currently I have a table "ComponentAnalysis" and a table "HistoryOfUse" that I am trying to map in Fluent NHibernate.

A component analysis should only have 1 history of use and a history of use should belong to 1 component analysis. This would suggest to me that the tables should be set up for a 1 to 1 mapping. But the designer of the DB didn't set it up that way.

Instead "HistoryOfUse" has a column "ComponentAnalysisID" to specify what component analysis it belongs to. To conform to the database I should have HistoryOfUse References ComponentAnalysis and ComponentAnalysis should HasMany HistoryOfUse.

But if I do this then I need to have a list of type HistoryOfUse which seems fairly annoying. Is there a way to set this up, without changing the database, to allow ComponentAnalysis to have a single HistoryOfUse object even though, according to the DB structure, it should have a list of them?

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

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

发布评论

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

评论(1

梅倚清风 2024-10-01 10:01:54

您可以使用 HasOne 方法来映射您的类。 这里是详细的文章关于这个。
您的 ComponentAnalysis 类将为“HasOne(x => x.HistoryOfUse)”。列 HistoryOfUse.ComponentAnalysisID 应该是唯一键,并且是引用 ComponentAnalysis.ID 列的外键。

You can use HasOne method to map your classes. Here is the detailed article about this.
Your class ComponentAnalysis will "HasOne(x => x.HistoryOfUse)". Column HistoryOfUse.ComponentAnalysisID should be a unique key and a foreign key referenced to the ComponentAnalysis.ID column.

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