I am using NHibernate 2.0.
I have a table with administrators and a table with phone numbers. I have a one-to-many relationship between these (i.e. an administrator can have many phone numbers).
This is represented in the domian model by the administrator having a PhoneNumberCollection of type ReadOnlyCollection<PhoneNumber>.
My mapping documents look like this:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="SecureDoxyLib" namespace="SecureDoxyLib.DomainLayer">
<class name="Administrator" table="aspnet_Employees">
<id name="UserId" column="UserId">
<generator class="guid" />
</id>
<component name="Address" class="Address">
<property name="Address1" type="String" column="Address1" not-null="true" />
<property name="Address2" type="String" column="Address2" not-null="false" />
<property name="Country" type="String" column="Country" not-null="true" />
<property name="FirstName" type="String" column="FirstName" not-null="true" />
<property name="MiddleName" type="String" column="MiddleName" not-null="false" />
<property name="LastName" type="String" column="LastName" not-null="true" />
<property name="PostalCode" type="String" column="PostalCode" not-null="true" />
<property name="City" type="String" column="City" not-null="true" />
<property name="State" type="SecureDoxyLib.DomainLayer.USStateType, SecureDoxyLib" column="State" not-null="false" />
</component>
<set name="PhoneNumberCollection">
<key column="UserId" />
<one-to-many class="PhoneNumber"/>
</set>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="SecureDoyxb" namespace="SecureDoxyLib.DomainLayer">
<class name="PhoneNumber" table="aspnet_PhoneNumbers">
<id name="PhoneId" column="PhoneId">
<generator class="identity" />
</id>
<property name="Category" type="SecureDoxyLib.DomainLayer.PhoneCategoryType, SecureDoxyLib" column="PhoneCategory" not-null="true" />
<property name="CountryCode" type="Int16" column="CountryCode" not-null="true" />
<property name="Number" type="Int64" column="PhoneNumber" not-null="true" />
</class>
</hibernate-mapping>
The problem is that all though the data is there in the table, the collection of phone numbers is always null on the administrator object. Does it have something to do with the type of collection on my domain object?