I recently used nhib.pdf and found that the total number of database records could not be obtained by querying by page. I found it online for a long time and did not find a specific implementation method. All the information I found was not very clear, after a long study, I finally wrote this method.
Icriteria is used to restrict the query conditions on the pages of NHibernate. However, only the number of records on the current page is returned, and the total number of records in the database cannot be returned. In this way, the total number of pages is not displayed during use. A custom page response object PageResponse is used to return the total number of records and the page query result set.
PageResponse <T> TotalCount {; IList <T> ResultList {;
Refer to the online method to create an ICriteria to query the total number of database records, and then cloneA PageResponse object defined by myself is returned for paging queries, including the total number of records and the paging query result set. Use it after obtaining the total number of database recordsUniqueResult () SetProjection ()
PageResponse <RequestMessage> GetRequestMessageList (pageNumber, (ISession session = session. CreateCriteria (= <RequestMessage> requestMessage = PageResponse <RequestMessage >=* (pageNumber <? : PageNumber-<RequestMessage>