title: How to implement ASP.NET Identity 2.0 in existing database?
body: <p>I'm currently having existing membership implemented in ASP.NET 4.5 web forms project. The application uses EntityFramework <code>6.1.3</code> version with <code>DbContext</code> and currently in Database first approach. I want to migrate the old membership to use the new ASP.NET identity 2.0 system. </p>
  
  <p>I have followed <a href="http://www.asp.net/identity/overview/migrations/migrating-an-existing-website-from-sql-membership-to-aspnet-identity" rel="nofollow noreferrer">this article</a> for performing the migration but never succeeded. I got the errors as mentioned in <a href="https://stackoverflow.com/q/29915487/1111430">The property &#39;Claims&#39; on type &#39;AspNetUser&#39; is not a navigation property</a>.</p>
  
  <p>It confirms that I'm missing something basic in the migration process.</p>
  
  <p><strong>Can someone provide me the step by step guide to perform the success migration?</strong></p>
  
  <p>I want to address the following points:</p>
  
  <p>1) In identity, I have some extra user data other than what default identity is providing. I see there is a <code>IdentityContext</code> which does these identity operations. I have a different context which inherits from <code>DbContext</code>. Do I need to use both the contexts? In other words <code>IdentityContext</code> is compulsory for identity operation? Cannot these two contexts be merged into one?</p>
  
  <p>2) I'm not restricted to Database first approach. Since the identity uses the code first approach I am okay to go ahead with the code-first approach but needs the correct steps to follow up.</p>
  
  <p>3) Since I have extra user data so I need to extend the <code>IdentityUser</code> to add new properties? If I will extend the <code>IdentityUser</code> will the identity code work seamlessly?</p>
  
  <p>4) I followed <a href="https://www.youtube.com/watch?v=blmkPA7XQf8" rel="nofollow noreferrer">https://www.youtube.com/watch?v=blmkPA7XQf8</a> video tutorial which adds the migration in the <code>ApplicationDbContext</code>. The ApplicationDbContext inherits <code>IdentityContext</code>. It worked for me but I want to add migration for my own context which inherits from DbContext. It's because the ApplicationDbContext doesn't include the other tables(non-identity tables).</p>
  
  <p>5) I tried applying the migration in my custom <code>Context.cs</code> file which contains all the identity and non-identity tables. I created this class using the reverse engineering approach by <a href="https://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d/" rel="nofollow noreferrer">EntityFramework Power Tools</a> as suggested in <a href="https://msdn.microsoft.com/en-us/data/jj593170.aspx" rel="nofollow noreferrer">this article</a>.</p>
  
  <p>After the POCO classes are created, I added migration and updated the database. The main errors I got are:</p>
  
  <pre><code>IdentityUserLogins: EntityType: EntitySet 'IdentityUserLogins' is based on type 'IdentityUserLogin' that has no keys defined. 
  
  IdentityUserRoles: EntityType: EntitySet 'IdentityUserRoles' is based on type 'IdentityUserRole' that has no keys defined.
  </code></pre>
  
  <p>As per this solution I added the configuration but ended up with creating new tables for IdentityUserLogin, IdentityRole etc. which are duplicate identity tables.</p>
  
  <p>6) Even if I'm keeping duplicate identity tables (e.g AspNetUserRoles and IdentityUserRole), I'm not able fetch data using the identity code
  <code>var user = userManager.FindAsync(UserName.Text, Password.Text);</code> and getting exception:</p>
  
  <pre><code>Invalid column name 'UserId'
  </code></pre>