为了在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 Exception,说我无法将Object转换为int32.
有关所需语法的任何想法?
编辑
Subquery使用distinct子句,我无法替换e.ID,e.Name with Count(*)
因为Count(*) distinct
不是有效的语法,并且distinct count(*)
没有意义.
NHibernate 3.0允许Linq查询.
试试这个
int count = session.QueryOver().RowCount();
var session = GetSession(); var criteria = session.CreateCriteria(typeof(Order)) .Add(Restrictions.Eq("Product", product)) .SetProjection(Projections.CountDistinct("Price")); return (int) criteria.UniqueResult();