I have modified the AspNetUsers table with additional address columns and have followed the steps here except the migration part. I started my project with the database first approach
My identity model has the additional fields
public class ApplicationUser : IdentityUser
{
public string Email;
public string Address;
public string City;
public string Province;
public string PostalCode;
}
In the AccountController I build my user like so:
var user = new ApplicationUser() {
UserName = model.UserName,
Email = model.Email,
Address = model.Address,
City = model.City,
Province = model.Province,
PostalCode = model.PostalCode
};
var result = await UserManager.CreateAsync(user, model.Password);
If I step through the code, I see that the user contains the new properties. However, when it saves, those fields are empty in the database. Is there something I missed or does the code-first migration do a step that haven't covered?
I'm certainly no ASP.NET Identity expert, still trying to get through the basics myself, but two suggestions come to mind.
First, I see you are adding fields to your ApplicationUser
class, not properties. This may be the problem. E.g., try changing
public string Email;
into
public string Email { get; set; }
Second, you will want to run the Migrations in order to get these columns added to your database. Although you did seem to say that you already have these columns in your database, so I don't think this step will add anything. (Since you said you started with a database-first approach. I am just mentioning this for the sake of completeness.)
Good luck to you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With