I tried this, but it does many selects..
In my code I use different names than above, but Container3 = Node, Scorecard = Tree.
This is how my mappings look like:
Code:
<class name="Container3" table="Containers">
<id name="Id" column="id">
<generator class="native" />
</id>
<many-to-one name="Parent"
column="parentId"
class="Container3" />
<bag name="Children" inverse="true">
<key column="parentId" />
<one-to-many class="Container3"/>
</bag>
<property name="ScorecardId" column="scorecardId" />
</class>
Code:
public class Container3
{
private int m_id;
public int Id
{
get { return m_id; }
set { m_id = value; }
}
private Container3 m_parent;
public Container3 Parent
{
get { return m_parent; }
set { m_parent = value; }
}
private IList m_children;
public IList Children
{
get { return m_children; }
set { m_children = value; }
}
private int m_scorecardId;
public int ScorecardId
{
get { return m_scorecardId; }
set { m_scorecardId = value; }
}
}
And this the criteria:
Code:
IList list = m_session.CreateCriteria(typeof(Container3))
.Add(Expression.Eq("ScorecardId", scorecardId))
.List();
The log:
NHibernate.Loader.Loader: 2006-01-27 15:45:00,599 [288] INFO NHibernate.Loader.Loader - SELECT this.id as id1_, this.parentId as parentId1_, this.scorecardId as scorecar5_1_, container31_.id as id0_, container31_.parentId as parentId0_, container31_.scorecardId as scorecar5_0_ FROM Containers this left outer join Containers container31_ on this.parentId=container31_.id WHERE this.scorecardId = @p0
NHibernate.Loader.Loader: 2006-01-27 15:45:00,630 [288] INFO NHibernate.Loader.Loader - SELECT children0_.parentId as parentId__, children0_.id as id__, children0_.id as id0_, children0_.parentId as parentId0_, children0_.scorecardId as scorecar5_0_ FROM Containers children0_ WHERE children0_.parentId=@p0
NHibernate.Loader.Loader: 2006-01-27 15:45:00,630 [288] INFO NHibernate.Loader.Loader - SELECT children0_.parentId as parentId__, children0_.id as id__, children0_.id as id0_, children0_.parentId as parentId0_, children0_.scorecardId as scorecar5_0_ FROM Containers children0_ WHERE children0_.parentId=@p0
NHibernate.Loader.Loader: 2006-01-27 15:45:00,645 [288] INFO NHibernate.Loader.Loader - SELECT children0_.parentId as parentId__, children0_.id as id__, children0_.id as id0_, children0_.parentId as parentId0_, children0_.scorecardId as scorecar5_0_ FROM Containers children0_ WHERE children0_.parentId=@p0
And so on...