I have the following class derived from IdentityUser. Person class is stored in AspNetUsers table in the database, and everything looks good on the database-side.
public class Person : IdentityUser
{
[Required]
[StringLength(50, ErrorMessage = "First name cannot be longer than 50 characters.")]
public string FirstName { get; set; }
[Required]
[StringLength(150, ErrorMessage = "Last name cannot be longer than 150 characters.")]
public string LastName { get; set; }
}
My questions is about creating a new user (Person) that has firstname and lastname. I guess, first I need to do this:
var user = new IdentityUser() { UserName = "testing" };
IdentityResult result = userManager.Create(user,"123456");
This will insert a new row to AspNetUsers table with null Firstname and Lastname fields. Then, by using LinQ, I need to update Firstname and Lastname fields of the existing record. Is this approach reasonable? Is there any other recommended way of doing this?
Since Person
is an IdentityUser
just do the following:
var user = new Person() { UserName = "xx", Firstname = "xy", Lastname = "yy" };
IdentityResult result = userManager.Create(user, "p@ssword");
This should handle everything necessary.