Fluent NHibernate Automappings 为 1 个关系生成 2 个外键
我有这个设置(为简洁起见而精简)
Class Employee
virtual IList<ChecklistItem> HasInitialed { get; private set; }
Class ChecklistItem
virtual Employee InitialedBy { get; set; }
生成后,我得到这些表
Employee
Id
ChecklistItem
Id
InitialedBy_id <----
Employee_id <----
ChecklistItem 有 2 个 Employee 外键,我假设 Employee_id 映射 ChecklistItem.Employee 和 InitialedBy_id 映射 ChecklistItem.InitialedBy。我如何告诉 NHibernate 这是相同的双向关系并且只需要 1 个外键?
一般来说,我对 NHibernate 比较陌生,但这似乎应该是相当标准的。
这是我在配置数据库以生成正确的架构时想到的,对吗?
.Override<Employee>(map => map
.HasMany<ChecklistItem>(x => x.HasInitialed)
.KeyColumn("InitialedBy_id"))
如果这是正确的,有没有办法根据 ChecklistItem 的属性名称(lambda)选择 KeyColumn?
I have this setup (condensed for brevity)
Class Employee
virtual IList<ChecklistItem> HasInitialed { get; private set; }
Class ChecklistItem
virtual Employee InitialedBy { get; set; }
When this is generated I get these tables
Employee
Id
ChecklistItem
Id
InitialedBy_id <----
Employee_id <----
The ChecklistItem has 2 foreign keys for Employee, I'm assuming Employee_id to map ChecklistItem.Employee and InitialedBy_id to map ChecklistItem.InitialedBy. How can I tell NHibernate that this is the same bidirectional relationship and only requires 1 foreign key?
I'm kind of new to NHibernate in general, but this seems like it should be pretty standard.
This is what I've come up with when I'm configuring my database to generate the right schema, is it right?
.Override<Employee>(map => map
.HasMany<ChecklistItem>(x => x.HasInitialed)
.KeyColumn("InitialedBy_id"))
If that is right, is there a way to choose KeyColumn based on the ChecklistItem's property name (a lambda)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为所有 hasmanies 的约定
或仅作为
Manytoone/References 的约定
as a convention for all hasmanies
or only for this
convention for Manytoone/References