title: How do i fix InvalidoperationException when querying EF code first database
body: <p>Query: </p>
  
  <pre><code>var user = db.Users.FirstOrDefault(u =&gt; u.Email.Equals(username) &amp;&amp; u.Password.Equals(password));
  </code></pre>
  
  <p>Error: </p>
  
  <pre><code>Local = 'db.Users.Local' threw an exception of type 'System.InvalidOperationException'
  </code></pre>
  
  <p>Detailed error message: </p>
  
  <blockquote>
    <p>Message = "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 D...
    Source: ""entityframework"
    StackTrace:StackTrace = "   at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()\r\n   at System.Data.Entity.Internal.InternalContext.Initialize()\r\n   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)\r\n   at System...</p>
  </blockquote>