Hmm. Having changed the mapping of the Employee class to include lazy="true", the objects produced by NHibernate now have null references for ReportsTo instead of the child Employee object. Here is my mapping:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="NHibernateTest.BusinessObjects.Employee, NHibernateTest.BusinessObjects" table="Employees" lazy="true">
<id name="Id" column="EmployeeID" type="Int32" access="nosetter.pascalcase-m-underscore">
<generator class="native" />
</id>
<property name="LastName" type="string" />
<property name="FirstName" type="string" />
<property name="Title" type="string" />
<property name="TitleOfCourtesy" type="string" />
<property name="BirthDate" type="date" />
<many-to-one name="ReportsTo" column="ReportsTo" />
</class>
</hibernate-mapping>
Here is my class:
Code:
public class Employee
{
private int m_Id;
private string m_LastName;
private string m_FirstName;
private string m_Title;
private string m_TitleOfCourtesy;
private DateTime m_BirthDate;
private Employee m_ReportsTo;
public int Id
{
get { return this.m_Id; }
}
public string LastName
{
get { return this.m_LastName; }
set { this.m_LastName = value; }
}
public string FirstName
{
get { return this.m_FirstName; }
set { this.m_FirstName = value; }
}
public string Title
{
get { return this.m_Title; }
set { this.m_Title = value; }
}
public string TitleOfCourtesy
{
get { return this.m_TitleOfCourtesy; }
set { this.m_TitleOfCourtesy = value; }
}
public DateTime BirthDate
{
get { return this.m_BirthDate; }
set { this.m_BirthDate = value; }
}
public Employee ReportsTo
{
get { return this.m_ReportsTo; }
set { this.m_ReportsTo = value; }
}
}
This is how I am accessing the object:
Code:
Employee Test = ((Employee) BaseFactory.LoadObject(typeof(Employee), 1)).ReportsTo;
which results in an object whose members are all null.
What am I doing wrong here?