如何使用NHibernate QueryOver API获取行数? [英] How do I get row count using the NHibernate QueryOver api?
本文介绍了如何使用NHibernate QueryOver API获取行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用NHibernate 3.x的QueryOver API.我想获取行计数,但是我正在使用的方法返回所有对象,然后获取集合的计数.有没有办法只返回行数的整数/长值?
I'm using the QueryOver api that is part of NHibernate 3.x. I would like to get a row count, but the method I'm using returns all objects and then gets the count of the collection. Is there a way to just return an integer/long value of the number of rows?
我当前正在使用:
_session.QueryOver<MyObject>().Future().Count()
推荐答案
在使用了api之后,可以做到这一点:
After a bit of playing around with the api, this will do it:
_session.QueryOver<MyObject>()
.Select(Projections.RowCount())
.FutureValue<int>()
.Value
如果您不想将来将其退还,则只需获取SingleOrDefault<int>()
.
If you don't want to return it as a future, you can just get the SingleOrDefault<int>()
instead.
这篇关于如何使用NHibernate QueryOver API获取行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文