Fluent NHibernate 的一对一映射不起作用
我有 2 个表(Labour 和 LabourPosition)。我不想使用 Labor 表中的 LabourPosition 表的 fki,而是使用对象 (theLabourer.LabourPosition.Name
而不是 getLabourPosition(theLabourer.LabourPositionId)
我已经阅读了几篇文章
来执行此操作,但它们似乎对我不起作用...尝试查看 LabourPosition 属性的值时遇到的错误是“无法初始化代理 - 没有会话”。
我的映射(ps:LabourPosition 没有返回到 Labour 的 fki,只有一种方式): LabourMap 类:
References<LabourPosition>(x => x.LabourPosition, "LabourPositionsId");
然后显然我已将 Labor 实体中的属性定义为:
public virtual LabourPosition LabourPosition { get; set; }
有什么想法吗?帮助将不胜感激!
I have 2 tables (Labour and LabourPosition). Instead of having a fki to the LabourPosition table from the Labour table, I'd like to use an object (theLabourer.LabourPosition.Name
instead of getLabourPosition(theLabourer.LabourPositionId)
.
I've read a few articles to do this but they don't seem to be working for me... the error I get when trying to view the value of the LabourPosition property is "Could not initialize proxy - no Session".
My mapping (p.s: LabourPosition does not have a fki back to Labour, one way only):
LabourMap class:
References<LabourPosition>(x => x.LabourPosition, "LabourPositionsId");
And then obviously I've defined the property in the Labour entity as:
public virtual LabourPosition LabourPosition { get; set; }
Any ideas? Help would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 流畅映射 文档
如果您想使用引用(如代码所示),则需要映射关系的双方。从文档中:
为什么需要一对一的关系,而不是仅将所有列保留在一个表中?
From the fluent mapping documentation
If you want to use a reference (as your code suggests), you need to map both sides of the relationship. From the documentation:
Why do you need a one-one relationship, instead of just keeping all the columns in a single table?
在你的映射中尝试
In your mapping try