title: Repository error - The context cannot be used while the model is being created
body: <p>I'm getting the following exception when trying to retrieve data from my registry:</p>
  
  <blockquote>
    <p>An exception of type 'System.InvalidOperationException' occurred in
    OHR.Repository.dll but was not handled in user code</p>
    
    <p>Additional information: The context cannot be used while the model is
    being created. This exception may be thrown if the context is used
    inside the OnModelCreating method or if the same context instance is
    accessed by multiple threads concurrently. Note that instance members
    of DbContext and related classes are not guaranteed to be thread safe.</p>
  </blockquote>
  
  <p>This error occurs on the first database query that I'm running in the method called MovieExists:</p>
  
  <p>MovieRepository.cs:</p>
  
  <pre><code>private readonly ApplicationDbContext _context;
  
  public MovieRepository(ApplicationDbContext context)
  {
      this._context = context;
  }
  
  public bool MovieExists(string MovieUrl)
  {
  
      try
      {
          bool result;
          using (_context)
          {
              // The next line causes the exception
              result = _context.Movies.Any(p =&gt; p.Url == MovieUrl);
          }
          return result;
      }
      catch (Exception e)
      {
          throw;
      }
  }
  </code></pre>
  
  <p>My context.cs</p>
  
  <pre><code>public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
  {
      public ApplicationDbContext()
          : base("DefaultConnection", throwIfV1Schema: false)
      {
      }
  
  
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          base.OnModelCreating(modelBuilder);
      }
  
      public virtual DbSet&lt;Movie&gt; Movies { get; set; }
  
  }
  </code></pre>
  
  <p>I'm using EF6, and while I have async EF tasks, this very first one is not using any async calls so I don't think I'm trying to use the context on multiple threads.</p>
  
  <p>I assume I'm not instantiating the context properly, but can't see how to fix the problem.</p>
  
  <p>Thanks</p>