Hi Luka,

I quote myself:

> What I need to do is retrieve the entire tree in one single 
> round-trip to the db and I can achieve that by loading the entire 
> table and letting the identity map works for me, it works like a charm.

Simply load the entire "table", e.g.:

var criteria = session.CreateCriteria<Node>()
        .CreateAlias( "ChildNodes", "cn" )
        .SetResultTransformer( ...distinct... );

var tree = criteria.List<Node>()
        .Where( n => n.Parent == null )
        .ToList();      

.m
___________________________________
Mauro Servienti  | Microsoft MVP - Visual C#
MCTS /MCPD | IM: [email protected]


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf
Of Luka
Sent: lunedì 27 settembre 2010 16:27
To: nhusers
Subject: [nhusers] Re: Filtering a recursive tree

Hi,
How did you manage to get the complete three in one query?
If I join with alias I get parent and child but not ie.
child.child.childrens. (4 level tree)


On Sep 27, 11:59 am, Mauro Servienti <[email protected]>
wrote:
> I solved the problem by myself :-)
>
> It's enought to create an alias for the ChildNodes and "emit" the same 
> restrictions on the alias as well.
>
> Really cool! I love NH :-)
>
> .m
>
> On Sep 27, 11:51 am, "Mauro Servienti" <[email protected]>
> wrote:
>
>
>
>
>
>
>
> > Hi all,
>
> > I have a simple tree like this one:
>
> > class Node
>
> > {
>
> >    String Name{ get; set; }
>
> >    Node Parent{ get; set; }
>
> >    IList<Node> ChildNodes{ get; set; }
>
> > }
>
> > What I need to do is retrieve the entire tree in one single 
> > round-trip to the db and I can achieve that by loading the entire 
> > table and letting the identity map works for me, it works like a charm.
>
> > Now I need to achieve the same result but issuing a where condition,
e.g.
> > filtering all the nodes whose Name starts with "Foo*". The query 
> > works fine and, using NH Proof, I can see that the correct list of 
> > Node(s) are loaded but then accessing to the ChildNodes property 
> > issues a new sql command to load children.
>
> > Is there a way to explain NH to use the same "condition" while 
> > loading the entire graph in order to go on using a single round-trip to
the db?
>
> > Thanks in advance, regards
>
> > .m
>
> > ___________________________________
>
> > Mauro Servienti  | Microsoft MVP - Visual C#
>
> > MCTS /MCPD- | IM: [email protected]
>
> >  smime.p7s
> > 8KViewDownload

--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to