4
We know that our user on Asp.net Identity is the class named after ApplicationUser
I would like to create other classes that inherit from her
Why?
Why, say I have the Customer, Seller, User class.
I want them all to be users of my system
So I have my default class that comes when creating the project:
public class ApplicationUser : IdentityUser
{
}
And I have my client class for example.
public class Cliente: ApplicationUser
{
public string CNPJ { get; set; }
}
When going to the Register action, I passed the Client to register as a user, since it inherits from Applicationuser:
public async Task<ActionResult> Register(Cliente model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser() {
UserName = model.UserName,
};
var result = await UserManager.CreateAsync(user, model.PasswordHash);
if (result.Succeeded)
{
await SignInAsync(user, isPersistent: false);
return RedirectToAction("Index", "Home");
}
else
{
AddErrors(result);
}
}
return View(model);
}
When I go to Action, I find the following mistake:
Invalid column name 'CNPJ'.
When trying to call the method CreateAsync(user,model.PasswordHash)
What am I doing wrong? Can I do what I’m doing? Inherit and have multiple classes like "user" in Identity?
PS: I’ve done Migrations and I’ve updated database
I have never tried something like this with so many layers of inheritance. I usually leave my applications at simplified layering levels. Suddenly I can try something.
– Leonel Sanches da Silva