I am using ASP.NET Core 2.2 Identity for my user management system.
I need to have several types of users ... for example, warehouse user and application user, which I create a base class that inherits from identity user class => IdentityUser<long>
public class BaseApplicationUser : IdentityUser<long>
{
public string FirstName { set; get; }
public string LastName { set; get; }
...
}
and warehouse user and store user inherit from BaseApplicationUser
to create different users.
public class ApplicationUser : BaseApplicationUser
{
}
I want to have just one table for all of them => AspNetUsers
on OnModelCreating
added this code :
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<ApplicationUser>();
builder.Entity<WarehouseApplicationUser>();
}
and in DbSets in Context :
public DbSet<ApplicationRole> ApplicationRole { get; set; }
public DbSet<ApplicationUser> ApplicationUsers { get; set; }
public DbSet<WarehouseApplicationRole> WarehouseApplicationRole { get; set; }
public DbSet<WarehouseApplicationUser> WarehouseApplicationUsers { get; set; }
I need to create separate role classes for the users, like ApplicationRole
and WarehouseApplicationUsers
.
Whats is the problem?
- How to create different users in asp.net core Identity? ( best way )
- Another problem is that when I add a field to
ApplicationUser
, that field is successfully added toAspNetUsers
, but when I add a field toWarehouseApplicationUsers
, EF Core adds new tables namedWarehouseApplicationUsers
andWarehouseApplicationRole
andWarehouseApplicationUserRole
and then adds a field to theWarehouseApplicationUsers
table... what is this!
And finally, how can I inherit and build a hierarchy of different users? Thanks a lot