Hello,

I'm wondering if there is a "good" way to perform an NHibernate query to 
load a forum (in its entirety).  I have the following object model:

Forum
{
int Id
List<Topic> Topics
}

Topic
{
int Id
Forum Forum
List<Post> Posts
}

Post
{
int Id
Forum Forum
Topic Topic
List<Post> Children
}

The following works quite efficiently in terms of database performance, but 
I can't get NHibernate to hydrate properly:

            var forum = Session
                .CreateQuery("select f from Forum f join fetch f.topics 
where f.Id = :forumId")
                .SetParameter("forumId", id)
                .UniqueResult<Forum>();

            var posts = Session
                .CreateQuery("select p from Post p join fetch p.User where 
p.Forum.Id = :forumId")
                .SetParameter("forumId", id)
                .List<Post>();

            foreach (var post in posts)
            {
                if (post.Parent == null)
                {
                    forum.Topics.First(t => t.Id == 
post.Topic.Id).Add(post);
                }
                else
                {
                    posts.First(p => p.Id == post.Parent.Id).Add(post);
                }
            }

            return forum;


Anyone have any tips?  The DistinctRootTransformer post I've seen does not 
solve this issue, as it can only do Parent->Child.  I Need infinite N 
levels of nesting.

Thanks for the help!

-- 
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