Stashing limit/offset query values before performing total pagination count

Some database engines return zero, when using the count aggregate on a query with limit and offset. Just followed the same pattern for stashing the 'orders' clause before performing a count on the query, and adding back to the query when done.
Merge pull request #4242 from jmshelby/4.1

Stashing limit/offset clause before performing total pagination count