Fluent nhibernate 流利的一对一关系?

Fluent nhibernate 流利的一对一关系?,fluent-nhibernate,nhibernate-mapping,Fluent Nhibernate,Nhibernate Mapping,我在流利的nHibernate中有一对一的关系问题 我从AdventureWorks2008数据库中获得了以下关系表 BusinessEntity (Table) BusinessEntityId Int (PK, Identity) Person (Table) BusinessEntityId int (PK, Reference with BusinessEntity table) FullName varchar(255) BusinessEntity表和Pers

我在流利的nHibernate中有一对一的关系问题

我从AdventureWorks2008数据库中获得了以下关系表

BusinessEntity (Table)
    BusinessEntityId Int (PK, Identity)

Person (Table)
   BusinessEntityId int (PK, Reference with BusinessEntity table)
   FullName varchar(255)
BusinessEntity表和Person表之间是一对一的关系

如何在Person表中没有任何像“Id”这样的额外字段的情况下流畅地映射


应该有两类,一类是个人,另一类是商业实体,或者有一个合适的模型来最好地描述上述关系

谢谢,
阿什拉夫

假设你的人物映射是相当标准的,你这样做的方式是说:

Id(x => x.BusinessEntityId)
     .GeneratedBy.Foreign("BusinessEntity");
关于Person类

这假定Person类有一个名为BusinessEntity的属性,该属性的类型为BusinessEntity

您还需要将BusinessEntity映射到constrated设置为true的Person(表示Person的主键是对BusinessEntity的外键引用)


关键是GeneratedBy.Foreign()表示您的身份是通过指向另一个类的链接生成的。

您的模型类是如何设置的?应该有两个类,一个用于Person,另一个用于BusinessEntity。或者一个合适的模型。示例公共类Person{public virtual BusinessEntity BusinessEntity{get;set;}公共虚拟字符串描述{get;set;}