class Comment {
ISet<Comment> Replies;
Guid Id;
Guid PostId;
DateTime Date;
Comment ParentComment;
bool IsCurrent
}
class CommentMap : ClassMap<Comment> {
CommentMap() {
Table("Comments");
Id(x => x.Id).GeneratedBy.GuidComb();
Map(x=>x.PostId);
Map(x=>x.Date);
Map(x=>x.IsCurrent);
References(x=>x.ParentComment).Column("ParentCommentId");
HasMany(x=>x.Replies).Column("ParentCommentId").Inverse().Cascada.All();
}
}
I need to load all ParentComment=null and IsCurrent=1 comments with each
hierarchy. I want to get comments desc ordered by date and limit 30 queries.
total root comment max 30,and each comment must IsCurrent=1
Root Comment 1
-Comment 1.1
--Comment 1.1.1
-Comment 1.2
Root Comment 2
-Comment 2.1
When I run below query, NHibernate generate 1 query, and get all root comments
with hierarchy. But I add IsCurrent condition nhibernate generate 2 seperate
queries.
var query = DbSession.CreateCriteria<Comment>()
.Add(Expression.Eq("PostId", postId))
.SetFetchMode("Replies", FetchMode.Eager)
.SetResultTransformer(new DistinctRootEntityResultTransformer())
.Future<Comment>();
var comments = query.Where(g => g.ParentComment == null);
--
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/groups/opt_out.