mrblah
mrblah

Reputation: 103577

how to get the total count of rows

from my previous question: 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)

Upvotes: 0

Views: 197

Answers (1)

Frederik Gheysels
Frederik Gheysels

Reputation: 56944

You'll have to use projections.

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

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

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

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

int result = crit.UniqueResult<int>();

Upvotes: 2

Related Questions