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.
