Add column to table with ASP.NET ID

I created a project with ASP.NET MVC in the authentication system. He created a new AspNetUsers table, but I want to add columns to this table, such as birthday, profile picture, etc. How can i do this?

Can I execute the query below in my SQL Server Management Studio?

 ALTER TABLE AspNetUsers ADD ProfilePicture NVARCHAR(100); ALTER TABLE AspNetUsers ADD BirthDay DATE; 

Or is it harder? I can’t work with the authentication infrastructure, so I have to do it using ADO.NET and the .NET framework 4.

+6
source share
2 answers

I found him! @James offered me an article that works.

Steps:

  • Enter this code in the console manager:

     Enable-Migrations 

    Source: blogs.msdn.com

  • In the ApplicationUser class, add the property you want.

     public DateTime? Birthdate { get; set; } 
  • in the console manager enter this code:

     Add-Migration "Birthdate" 
  • After updating the database with this code:

     Update-Database 

Result: A new column named “Date of birth” has been added to the database and enter a datetime , which may be zero.

+15
source

Suppose you want to add a new column named "FirstName":

Step 1: Models /IdentityModels.cs

Add the following code to the "ApplicationUser" class:

 public string FirstName { get; set; } 

Step 2: Models /AccountViewModels.cs

Add the following code to the "RegisterViewModel" class:

 public string FirstName { get; set; } 

Step 3: Views / Register.cshtml

Add the FirstName input text box to the view:

 <div class="form-group"> @Html.LabelFor(m => m.FirstName, new { @class = "col-md-2 control-label" }) <div class="col-md-10"> @Html.TextBoxFor(m => m.FirstName, new { @class = "form-control" }) </div> </div> 

Step 4:

Go to Tools> NuGet Manager> Package Manager Console

Step A: Type “Enable-Migrations” and hit enter
Step B: Type "Add-Migration" FirstName "and press enter
Step C: Type "Update Database" and press Enter
i.e

 PM> Enable-Migrations PM> Add-Migration "FirstName" PM> Update-Database 

Step 5: Controllers /AccountController.cs

Go to the "Registry" action and add "FirstName = model.FirstName" to ApplicationUser ie

 var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName} 
+6
source

All Articles