title: Change ASP.NET Identity to use existing database
body: <p>I'm using ASP.NET MVC 5 with a Database-First workflow. I've created the Identity tables (<code>AspNetUsers</code>, <code>AspNetRoles</code> etc.) in my existing database however I'm having problems getting the <strong>register</strong> and <strong>login</strong> functionality to work properly. </p>
  
  <p>This is the <code>IdentityModels.cs</code> class</p>
  
  <pre><code>public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
  {
      public ApplicationDbContext()
          : base("MyConnectionString") // I use "MyConnectionString" instead of "DefaultConnection" 
      {
      }
  </code></pre>
  
  <p>This is what the EF connection string from the <code>web.config</code> looks like</p>
  
  <pre><code>&lt;connectionStrings&gt;&lt;add name="MyConnectionString" connectionString="metadata=res://*/Entities.MyModel.csdl|res://*/Entities.MyModel.ssdl|res://*/Entities.MyModel.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;data source=My-Pc\SQLEXPRESS;initial catalog=MyExistingDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&amp;quot;" providerName="System.Data.EntityClient" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>And for good measure here's the context class generated from the edmx</p>
  
  <pre><code>public partial class MyConnectionString : DbContext
  {
      public MyConnectionString()
          : base("name=MyConnectionString")
      {
      }
  </code></pre>
  
  <p>To me all seems well and it should be able to create users in the database however I'm getting the following error when logging in or trying to register respectively:</p>
  
  <p>For login:</p>
  
  <blockquote>
    <p>The entity type ApplicationUser is not part of the model for the
    current context</p>
    
    <p>Line 73: var result = await SignInManager.PasswordSignInAsync(model.Email,
    model.Password, model.RememberMe, shouldLockout: false);</p>
    
    <p>Exception Details: System.InvalidOperationException: The entity type
    ApplicationUser is not part of the model for the current context.</p>
  </blockquote>
  
  <p>For register:</p>
  
  <blockquote>
    <p>The entity type ApplicationUser is not part of the model for the
    current context</p>
    
    <p>Line 155: var result = await UserManager.CreateAsync(user,
    model.Password);</p>
    
    <p>Exception Details: System.InvalidOperationException: The entity type
    ApplicationUser is not part of the model for the current context.</p>
  </blockquote>
  
  <p>Most articles around seems to be focusing on Code-First and how to go from LocalDb to SQLExpress etc. and how to change the connection string however I haven't been able to solve this problem for a good amount of time.</p>
  
  <p><strong>Edit, solution</strong>: As @ChrFin mentioned you could use them both side by side which is what I ended up doing. I simply added a new <a href="http://msdn.microsoft.com/en-us/data/jj556606.aspx" rel="nofollow"><em>regular</em></a> connection string in <code>web.config</code> and let it point to the existing database. PS. remember that the connection string name cannot be the same as the existing one and must be the same you provide to the <code>ApplicationDbContext</code> constructor.</p>