如何选择 nHibernate 子查询结果的 Count(*) [英] How do I select the Count(*) of an nHibernate Subquery's results
本文介绍了如何选择 nHibernate 子查询结果的 Count(*)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为了在 nHibernate 中分页查询,我需要执行以下操作:
I need to do the following for the purposes of paging a query in nHibernate:
Select count(*) from
(Select e.ID,e.Name from Object as e where...)
我尝试了以下方法,
select count(*) from Object e where e = (Select distinct e.ID,e.Name from ...)
并且我收到一个 nHibernate 异常,说我无法将 Object 转换为 int32.
and I get an nHibernate Exception saying I cannot convert Object to int32.
对所需语法有任何想法吗?
Any ideas on the required syntax?
编辑
子查询使用不同的子句,我不能用 Count(*)
替换 e.ID,e.Name 因为 Count(*) distinct
不是有效的语法,distinct count(*)
没有意义.
The Subquery uses a distinct clause, I cannot replace the e.ID,e.Name with Count(*)
because Count(*) distinct
is not a valid syntax, and distinct count(*)
is meaningless.
推荐答案
NHibernate 3.0 允许 Linq 查询.
NHibernate 3.0 allows Linq query.
试试这个
int count = session.QueryOver<Orders>().RowCount();
这篇关于如何选择 nHibernate 子查询结果的 Count(*)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文