NHibernate: getting the available row count while using maxResults
-
Hi, I've done some hibernate work querying data from oracle. Since the return might be a very huge list of objects, I use the SetMaxResults() method.
int maxDS = 1000;
ISession session = //..
ICriteria criteria = session.CreateCriteria(typeof(Trade));
criteria.SetMaxResults(maxDS);
AddCriterions(criteria); // I add some criterions in this method
IList<Trade> trades = criteria.List<Trade>();How can I get the number of totally available objects (for my criterions) without disposing maxDS and loading them all? Thanks in advance.
-
Hi, I've done some hibernate work querying data from oracle. Since the return might be a very huge list of objects, I use the SetMaxResults() method.
int maxDS = 1000;
ISession session = //..
ICriteria criteria = session.CreateCriteria(typeof(Trade));
criteria.SetMaxResults(maxDS);
AddCriterions(criteria); // I add some criterions in this method
IList<Trade> trades = criteria.List<Trade>();How can I get the number of totally available objects (for my criterions) without disposing maxDS and loading them all? Thanks in advance.
I've found the solution:
criteria.SetProjection(Projections.RowCount());
int totalRecordsFound = (int)criteria.UniqueResult();