Search code examples
.netasp.net-mvcasp.net-identity

.Net Identity - Field from super class is not saved to DB


I want to have more types of users with different fields in Identity. User has a Name, PIN and Employee has also Name, and Department.

I created an AppUser to store the common fields (e.g. Name), which is an IdentityUser

AppUser : IdentityUser {
   public String Name;
}

And I tried to derive my real users (User, Employee) from them.

User : AppUser{
   public String PIN; 
}

Employee: AppUser{
   public String Department;
}

Althought this does not seem to work, the Name field is not persisted to DB when I seed the DB.

Is this approach wrong? How else should I do this? What am I missing?


Solution

  • Entity Framework generate DataBase column corresponding Property of a class not Field. So try like

    public class AppUser : IdentityUser {
       public String Name { get; set; }
       public String PIN { get; set; }
    }