Skip to content

Instantly share code, notes, and snippets.

Created March 19, 2011 15:18
What would you like to do?
How to eager load Child Collections (Ex: Blog.Post.Comments) Directly Using QueryOver In NHibernate 3.1
.Fetch(b => b.Posts).Eager // If you don't add this, the following will not work
.Fetch(b => b.Posts.First().Comments).Eager // The trick here is using ".First()" after the collection
Copy link

Meligy commented Mar 19, 2011

Result Query (SQL CE 4.0):

    this_.Id as Id0_2_,
    this_.Title as Title0_2_,
    posts2_.Blog_id as Blog3_4_,
    posts2_.Id as Id4_,
    posts2_.Id as Id2_0_,
    posts2_.Title as Title2_0_,
    comments3_.Post_id as Post3_5_,
    comments3_.Id as Id5_,
    comments3_.Id as Id1_1_,
    comments3_.Title as Title1_1_
    "Blog" this_
left outer join
    "Post" posts2_
        on this_.Id=posts2_.Blog_id
left outer join
    "Comment" comments3_
        on posts2_.Id=comments3_.Post_id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment