如何选择nHibernate子查询结果的Count(*) [英] How do I select the Count(*) of an nHibernate Subquery's results

查看:110
本文介绍了如何选择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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆