I have this working query in HQL:
select new PostSummary(p.Id, p.Title, p.DateCreated, p.DatePublished,
count(comments)) from PostEntity p
left join p.Comments comments
group by p.Id, p.Title, p.DateCreated, p.DatePublished
order by p.DateCreated desc
I would like to create this query with the Criteria API but am having
trouble with the count of the comments part. This is what I have now:
DetachedCriteria criteria =
DetachedCriteria.For<PostEntity>("p");
criteria
.CreateCriteria("Comments", JoinType.LeftOuterJoin);
criteria.SetProjection(
Projections.ProjectionList()
.Add(Projections.GroupProperty("p.Id"))
.Add(Projections.GroupProperty("p.Title"))
.Add(Projections.GroupProperty("p.DateCreated"))
.Add(Projections.GroupProperty("p.DatePublished"))
.Add(Projections.Count(Projections.Property
("p.Comments")))
);
criteria
.AddOrder(Order.Desc(Projections.Property
("p.DateCreated")))
.AddOrder(Order.Asc(Projections.Property("p.Title")));
criteria.SetResultTransformer(new
TypedResultTransformer<PostSummary>());
When looking at the SQL the count is reference this_id instead of the
comments id.
How do I get the comments count with the Criteria API?
Thanks,
Joe
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---