title: The context cannot be used while the model is being created
body: <p>In my application I receive the following error:</p>
  
  <blockquote>
    <p>The context cannot be used while the model is being created.</p>
  </blockquote>
  
  <p>I'm not sure what this means. I have done everything as normal and usually it works but for this one it isnt. Below is my code:</p>
  
  <p>App.config:</p>
  
  <pre class="lang-xml prettyprint-override"><code> &lt;connectionStrings&gt;
      &lt;add name="DatabaseContext" connectionString="Data Source=./SQLEXPRESS;Initial Catalog=ProjectCode;Integrated Security=SSPI;" providerName="System.Data.SqlClient" /&gt;
   &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>Products.cs:</p>
  
  <pre><code>class Products
  {
      public int ProductID { get; set; }
      public string ProductName { get; set; }
  }
  </code></pre>
  
  <p>DatabaseContext.cs:</p>
  
  <pre><code>class DatabaseContext : DbContext
  {
      public DbSet&lt;Products&gt; Products { get; set; }
  }
  </code></pre>
  
  <p>Program.cs:</p>
  
  <pre><code>DatabaseContext context = new DatabaseContext();
  
  try
  {
     var products = context.Products.ToList();
  
     foreach (var item in products)
     {
        Console.WriteLine(item.ProductID + " : " + item.ProductName);
     }
        Console.ReadLine();
  }
  </code></pre>
  
  <p>The line is fails on is <code>var products = context.Products.ToList();</code></p>
  
  <p>Any ideas what could be causing this? I have set up 2 products in my database so it should be outputting them.</p>
  
  <h2>EDIT</h2>
  
  <p>Here is my whole App.config file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /&gt;
    &lt;/configSections&gt;
    &lt;connectionStrings&gt;
      &lt;add name="DatabaseContext" connectionString="Data Source=./SQLEXPRESS;Initial Catalog=ProjectCode;Integrated Security=SSPI;MultipleActiveResultSets=true" providerName="System.Data.SqlClient" /&gt;
    &lt;/connectionStrings&gt;
    &lt;startup&gt;
      &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
    &lt;/startup&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"&gt;
        &lt;parameters&gt;
          &lt;parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True" /&gt;
        &lt;/parameters&gt;
      &lt;/defaultConnectionFactory&gt;
    &lt;/entityFramework&gt;
  &lt;/configuration&gt;
  </code></pre>