Thanks Richard, your answer is very helpful to me. 在 2013年3月16日星期六UTC+8下午8时38分49秒,Richard (gmail)写道: > > Hi, > > I think the syntax is: > > session.QueryOver<Parent>() > .Fetch(p => p.Children).Eager > .Fetch(p => p.Children[0].GrandChilden).Eager > .List(); > > (Note, you don’t need List<Parent>(), just List() is enough when it > matches the root query type). > > If your collection is exposed as an IEnumerable, then you can use: > > session.QueryOver<Parent>() > .Fetch(p => p.Children).Eager > .Fetch(p => p.Children.First().GrandChilden).Eager > .List(); > > > https://github.com/nhibernate/nhibernate-core/blob/master/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs#L731-L732 > > > https://github.com/nhibernate/nhibernate-core/blob/master/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs#L107 > > Hope that helps. > > Cheers, > Richard > > > *From:* MiNG <javascript:> > *Sent:* Thursday, March 14, 2013 2:13 AM > *To:* [email protected] <javascript:> > *Subject:* [nhusers] How to fetch grandchildren by ISession.QueryOver<T>() > > I have following entities: > > public class Parent > { > public virtual Int32 Id {get; set;} > public virutal IList<Child> Children {get; set;} > } > > public class Child > { > public virtual Int32 Id {get; set;} > public virtual Parent Parent {get; set;} > public virtual IList<GrandChild> GrandChildren {get; set;} > } > > public class GrandChild > { > public virtual Int32 Id {get; set;} > public virtual Child Child {get; set;} > } > > When using ICriteria, I can fetch the GrandChild by using SetFetchMode() > like: > session.CreateCriteria<Parent>() > .SetFetchMode("Children", FetchMode.Eager) > .SetFetchMode("Children.GrandChildren", FetchMode.Eager) > .List<Parent>(); > > Now I want to convert the above code to using QueryOver API, but I cannot > find the way to fetch the grandchildren except using the complex join > methods (e.g. JoinAlias() or JoinQueryOver()). > Is there any way that can fetch the grandchildren easily ? > -- > 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] <javascript:>. > To post to this group, send email to [email protected] <javascript:> > . > Visit this group at http://groups.google.com/group/nhusers?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > >
-- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
