开发者

how to get the total count of rows

开发者 https://www.devze.com 2022-12-15 02:35 出处:网络
from my previous question: multiple results in a single call how would I get the count of all articles in a given categ开发者_运维技巧ory?

from my previous question: multiple results in a single call

how would I get the count of all articles in a given categ开发者_运维技巧ory?

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


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>();
0

精彩评论

暂无评论...
验证码 换一张
取 消