tags:

views:

36

answers:

1

from my previous question: http://stackoverflow.com/questions/1947026/multiple-results-in-a-single-call

how would I get the count of all articles in a given category?

I prefer criteria query if possible (would love it if you could show me how to do it in both criteria and hql)

+2  A: 

You'll have to use projections.

I believe, you'll have to create a criteria which will look somethink like this:

ICriteria crit = mySession.CreateCriteria (typeof(Article));

crit.Add (Restrictions.Eq ("Category", someCategory));

crit.SetProjection (Projections.Count("somePropertyNameOfArticle"));

int result = crit.UniqueResult<int>();
Frederik Gheysels
+1 you could do a Projections.RowCount (i.e. count(*)) here since we're not grouping by anything.
dotjoe