使用表定义:
Employee
EmployeeId Primary Key
LastName
FirstName
EmployeeAddress
EmployeeAddressId
EmployeeId
Address
City
的类定义
public class Employee
{
public int EmployeeId {get; set;}
public string LastName {get; set;}
public string FirstName {get; set;}
public EmployeeAddress EmployeeAddress {get; set;}
}
应该使用什么类型的映射来填充Employee.EmployeeAddress。我的第一次尝试是
Reference(x=>x.EmployeeAddress).Column("EmployeeId")
以
生成连接Employee.EmployeeId = EmployeeAddress.EmployeeAddressId
我可以使用Join来做吗?像
这样的东西Join("EmployeeAddress", join => join.Map(x => x.EmployeeAddress).
调用configure时会生成错误。我似乎只能使用Join来获取个人属性,而不是类。如果我在地址和城市的Employee类中添加属性然后映射那些属性,我可以加入工作,但我想将它映射为一个类而不是每个单独的属性。
答案 0 :(得分:0)
我不知道Fluent语法(对于one-to-one
它是HasOne
而对于many-to-one
它是References
),但这是生成的XML:
<class name="Employee">
<id name="EmployeeId">
<generator class="..." />
</id>
<property name="FirstName" />
...
<one-to-one name="EmployeeAddress" cascade="all" property-ref="Employee" />
</class>
<class name="EmployeeAddress">
<id name="EmployeeAddressId">
<generator class="..." />
</id>
<property name="Address" />
...
<many-to-one name="Employee" column="EmployeeId" unique="true" cascade="all" />
</class>