title: How to move the KnpPaginator manual count to Repository class?
body: <p>I am using <strong><em>knppaginator</em></strong> to paginate a very large collection of entities, after not being happy with the performance I realized that they would fetch all the entities regardless of what page number was being passed, I inspected the query profiler and I never saw any offsets in the query. Anyway, this is what I found that works but I would like to move the part where I get the count and the entities back to the repository class, where I would like to use <strong>createQueryBuilder</strong> instead.</p>
  
  <pre><code>public function indexAction(Request $request)
  {
  
      $page = $request-&gt;get('p', 1);
  
      $this-&gt;breadcrumbs(
          array(
              array('title'=&gt;'Admin','path'=&gt;'home'),
              array('title'=&gt;'Customers','path'=&gt;'customers'),
              array('title'=&gt;'All'),
          )
      );
  
      $em = $this-&gt;getDoctrine()-&gt;getManager();
  
  
      $count = $em
          -&gt;createQuery('SELECT COUNT(cb) FROM MWCoreBundle:ContactsBasics cb LEFT JOIN cb.login l LEFT JOIN cb.setting s')
          -&gt;getSingleScalarResult()
      ;
  
      $entities = $em
          -&gt;createQuery('SELECT cb,l,s FROM MWCoreBundle:ContactsBasics cb LEFT JOIN cb.login l LEFT JOIN cb.setting s ORDER BY cb.dateAdded DESC')
          -&gt;setHint('knp_paginator.count', $count);
  
  
      $pagination = $this-&gt;get('knp_paginator')-&gt;paginate($entities, $page, 50, array('distinct' =&gt; false));
  
  
      return $this-&gt;render('MWCoreBundle:ContactsBasics:index.html.twig', array(
          'entities' =&gt; $entities,
          'pagination' =&gt; $pagination,
      ));
  }
  </code></pre>