简体   繁体   中英

Projections.RowCountInt64() returns 0 when i set SetFirstResult

rowCount returns 0 when query.SetFirstResult is different from 0 ?

if the result of pageIndex x pageSize = 0 // it gives me the rowCount but when it is not equal to 0, countCriteria gives me 0 instead of rowCount.

What can i do ?

Thanks in advance

First thing would be to use a sqlprofiler and check the sql that is getting executed. Maybe there's something wrong with that. I can't see something wrong in the criteria.

I have solved my problem. The thing is, there is a buggy staff with Nhibernate about CriteriaTransformer.TransformToRowCount . It returns int not long.

And what i did wrong above is, i was trying to get the row count of limited result set(the query on which SetFirstResult and SetMaxResult setted)

ISession session = NHibernateHttpModule.CurrentSession;

            var countCriteria = CriteriaTransformer.TransformToRowCount(query);
            rowCount = Convert.ToInt64(countCriteria.GetExecutableCriteria(session).UniqueResult());

            query.SetMaxResults(pageSize).SetFirstResult(pageIndex * pageSize);
            var customers = query.GetExecutableCriteria(session).List<Customer>();

This is the solution for my scenerio. I hope it helps someone who has the same issue.

Thaks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM