First of all, you should declare your List<Child>
as IList<Child>
, because NHibernate needs to be able to use its own collection-type that implements IList.
In your mapping, you should use the 'bag' element to map your List. (Are you sure you want to use a List and not a Set ? Since a List allows that one single entity occurs more then once in the list, whereas a Set does not allow that).
This is how I should do it:
public class Parent
{
private IList<Child> _children = new List<Child>();
public ReadOnlyCollection<Child> Children
{
get {return _children.AsReadOnly();}
}
}
And the mapping:
<class name="Parent" table="Parent">
<list name="Children" table="..." access="field.camelcase-underscore" inverse="true">
<key column="..." />
<one-to-many class="Child" />
</list>
</class>
(Ommitted al the other properties for brevity)
(Ow, now that I see it, you're using Hibernate ? My code example is in C#, so I do not know whether you have the notion of ReadOnlyCollection etc...)