save new data to user table using asp identity

2019-09-20 00:45发布

问题:

I am trying to add a piece of data to the Asp identity table which stores user details (AspNetUsers). I have code to create a new user but not how to add or change things in a table. Could someone link me a resource or show me an example of how to do this?

For example if I created users where age was null and had a form that asked a user to input an age and wanted to add that to the users information without having to create a new user.

I have all the code to collect the variable.

I have added migrations for the new columns and created the columns in the table, I just need to add the data for the user that is currently logged in.

回答1:

Have you tried this

var user = await UserManager.FindByNameAsync(User.Identity.Name);
user.Age = 25;
IdentityResult result = await UserManager.UpdateAsync(user);