title: nhibernate paging with detached criteria
body: <p>I am working on an application in which I would like to implement paging.  I have the following class that implements detached criteria - </p>
  
  <pre><code>public class PagedData : DetachedCriteria
      {
          public PagedData(int pageIndex, int pageSize) : base(typeof(mytype))
          {
  
              AddOrder(Order.Asc("myId"));
  
              var subquery = DetachedCriteria.For(typeof(mytype2))
                  .SetProjection(Projections.Property("mytype.myId"));
  
              Add(Subqueries.PropertyIn("myId", subquery));
  
              SetFirstResult((pageIndex - 1) * pageSize);
              SetMaxResults(pageSize);   
          }
      }
  </code></pre>
  
  <p>This works fine - it returns exactly the data that I am trying to retrieve.  The problem I am running into is getting the total row count for my page navigation.  since I am using the setfirstresults and setmaxresults in my detached criteria, the row count is always limited to the pageSize variable that is coming in.  </p>
  
  <p>My question is this:  How can I get the total row count?  Should I just create another detachedcriteria to calculate the row count?  If so, will that add round trips to the db?  Would I be better off not using detacedcriteria and using a straight criteria query in which I can then utilize futures?  Or can I somehow use futures with what I am currently doing. </p>
  
  <p>Please let me know if any further information is needed.</p>
  
  <p>Thanks</p>