It really depends on how you're using the tree. On strategy I've used is to
rely on in memory operations to recreate the tree. Works very well in my
limited scenario,

var allNodes=session.Query<Lead>().Fetch(x => x.Parent).ToList();

var
tree=allNodes.Where(x=>x.Parent==null).Select(x=>ReCreateLead(x,allNodes));

private Lead ReCreateLead(Lead lead,List<Lead> allLeads){
return new
Lead{Id=lead.Id,Code=lead.Code,Parent=lead.Parent,Children=allLeads.Where(x=>x.Parent==lead).Select(x=>ReCreateLead(x,allLeads)).ToList()};
}



2014-09-10 15:47 GMT+02:00 Alexander Zaytsev <[email protected]>:

> Hi David,
>
> Please check my article on that question
>
>
> http://alexzaytsev.me/2013/03/04/nhibernate-how-to-persist-tree-like-structures/
>
> Best regards,
> Alexander
> 10.09.2014 22:14 пользователь "David Perfors" <[email protected]>
> написал:
>
> In 2009 Ayende wrote a post about efficiently loading a tree using HQL (
>> http://ayende.com/blog/4151/nhibernate-tips-tricks-efficiently-selecting-a-tree
>> )
>> I am trying to translate this into a Linq query, but it doesn't give me
>> the same results.
>>
>> I've got the following object:
>>
>> public class Lead
>> {
>>      public Lead()
>>      {
>>              Children = new List<Lead>();
>>      }
>>      public virtual int ID { get; protected set; }
>>      public virtual string Code { get; set; }
>>      public virtual Lead Parent { get; set; }
>>      public virtual IList<Lead> Children { get; protected set; }
>> }
>>
>> With the following mapping:
>>
>> public class LeadMap : ClassMap<Lead>
>> {
>>      public LeadMap()
>>      {
>>              Id(x => x.ID);
>>              Map(x => x.Code);
>>              References(x => x.Parent).Cascade.None();
>>              HasMany(x => x.Children)
>>                      .KeyColumn("ParentID")
>>                      .Cascade.All()
>>                      .Inverse()
>>                      .OrderBy("SortOrder, Code");
>>      }
>> }
>>
>> But when I do:
>>
>> session.Query<Lead>().FetchMany(x => x.Children).ToArray();
>>
>> I still go to the database everytime I enumerate over Children.
>> I also tried to set LazyLoading to false on Children and different kind
>> of queries, but it doesn't seem to work.
>>
>> The reason I don't use the HQL is that we do some joining and some
>> filtering based on another referenced type and since we are so used to
>> Linq, we don't want to let it go. When we have to we will of course...
>>
>> Any ideas?
>>
>> David.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "nhusers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/nhusers.
>> For more options, visit https://groups.google.com/d/optout.
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/nhusers.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to