Thanks for the help... In the end others decided that the use of collection in combination with NHibernate was giving us to much overhead when loading and saving, so the decision was made to remove all collections on all objects (except the difficult ones and some of the many-to-many ones) and replace them with an "intelligent" property that can go to the database and get the collection. (basically SomeObject.Session.Query<Lead>().Where(x => x.Parent == this); ) Don't ask me why, but others find this more useful and faster...
B.t.w. Recardo, thanks for providing that pull request so quickly :) On Tuesday, 9 September 2014 16:30:04 UTC+2, David Perfors wrote: > > 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.
