Hi
I would like to build a tree of Organisations. I use the following mapping and class.
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Foundation.DomainModels.Organisation, Foundation" table="Organisation" lazy="true">
<id name="Id" column="ID" type="Int32" unsaved-value="0">
<generator class="native" />
</id>
<property name="Text" column="d_Text" type="String" length="50" />
<many-to-one name="Parent" column="ParentID" class="Foundation.DomainModels.Organisation" />
<set name="Children">
<key column="ParentID" foreign-key="ID"/>
<one-to-many class="Foundation.DomainModels.Organisation"/>
</set>
</class>
</hibernate-mapping>
public class Organisation {
public virtual int Id { get; set; }
public virtual string Text { get; set; }
public virtual Organisation Parent { get; set; }
public virtual ISet<Organisation> Children { get; set; }
}
What is the best way for reading the data with eager loading? I've tried something like this, but without success.
session.CreateCriteria<Organisation>()
.SetFetchMode("Parent", FetchMode.Eager)
.SetFetchMode("Children", FetchMode.Eager)
.List<Organisation>();
On this way not all data was loaded...
Thanks