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...)
I have tried the following,
select count(*) from Object e where e = (Select distinct e.ID,e.Name from ...)
and I get an nHibernate Exception saying I cannot convert Object to int32.
Any ideas on the required syntax?
EDIT
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.
var session = GetSession();
var criteria = session.CreateCriteria(typeof(Order))
.Add(Restrictions.Eq("Product", product))
.SetProjection(Projections.CountDistinct("Price"));
return (int) criteria.UniqueResult();
NHibernate 3.0 allows Linq query.
Try this
int count = session.QueryOver<Orders>().RowCount();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With