FluentNhibernate Joined Class
With the table definition:
Employee
EmployeeId Primary Key
LastName
FirstName
EmployeeAddress
EmployeeAddressId
EmployeeId
Address
City
And class definition of
public class Employee
{
public int EmployeeId {get; set;}
public string LastName {get; set;}
public string FirstName {get; set;}
publi开发者_如何学Cc EmployeeAddress EmployeeAddress {get; set;}
}
What type mapping should be used to populate Employee.EmployeeAddress. My first attempt was
Reference(x=>x.EmployeeAddress).Column("EmployeeId")
that generates the join as
Employee.EmployeeId = EmployeeAddress.EmployeeAddressId
Can I use Join to do it? Something like
Join("EmployeeAddress", join => join.Map(x => x.EmployeeAddress).
That generates an error when configure is called. It seems I can only use Join for individual properties and not the class. I can get Join to work if I add properties in the Employee class for Address and City and then map those, but I want to map it as a class not each individual property.
I don't know the Fluent syntax (for one-to-one
it's HasOne
and for many-to-one
it's References
), but this is the resulting 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>
精彩评论