Add column to aspnetusers with database first

I found many tutorials for adding columns to Identity tables (which I successfully moved to the application database) with database migrations, however I understand that this is not applicable in database bush projects. So ... how to add columns to the aspnetusers table in the first database project?

I would like to declare a column type bit named Is RegComplete, which is initially set to 0, and then at some point when the user has completed a few more tasks, set the value to 1.

+6
source share
2 answers

Ok, I hacked it! First, I did not understand that although I moved the Identity tables to the application database, there are still two database contexts: one for application tables that are DB First, and the other for Identities tables.

I was able to enable the migration and first add the column using the code and then perform the migration and then update the database. The new column is now available in the controller.

I found this tutorial that helped me: http://blogs.msdn.com/b/webdev/archive/2013/10/16/customizing-profile-information-in-asp-net-identity-in-vs-2013 - templates.aspx

+5
source

The simplest solution:

  • Adding Columns to an AspNetUsers Table
  • Add properties to the IdentityModels.cs class (Check attachment)
  • Add the same properties to AccountViewModels.cs\RegisterViewModel
  • Compilation and it will work.

application enter image description here

(VS 2017, MVC5)

+1
source

Source: https://habr.com/ru/post/984038/


All Articles