title: Symfony2: Using a repository in a command
body: <p>I'm using Symfony2 (2.6) and I want to use a custom repository of a Contact entity in a command whose name is CRM:fetchEmails.</p>
  
  <p>I tried two different methods in order to get the repository:</p>
  
  <p>First method:</p>
  
  <p>In the execute function of my command file</p>
  
  <pre><code>$repository = $this-&gt;getContainer()-&gt;get('doctrine')-&gt;getEntityManager()-&gt;getRepository('CRMBundle:Contact');
  </code></pre>
  
  <p>Second method:</p>
  
  <p>In the execute function of my command file</p>
  
  <pre><code>$repository = $this-&gt;getContainer()-&gt;get('myrepository');
  </code></pre>
  
  <p>And in config.yml</p>
  
  <pre><code>myrepository:
      class: Doctrine\ORM\EntityRepository
      factory: [@doctrine.orm.entity_manager, getRepository]
      arguments:
          - CRMBundle\Entity\Contact
  </code></pre>
  
  <p>Either with the first or second method I get this error when executing the command:</p>
  
  <pre><code> [Symfony\Component\Debug\Exception\ContextErrorException] Notice: Undefined property: Doctrine\ORM\Configuration::$getRepository CRM:fetchEmails [name] 
  </code></pre>
  
  <p>Does anyone know how to solve my problem?</p>