Hi,
I'm building a multi tenant application with dot net core and would like to try to use identity core infraestructure. First, I will try to summarize my DB design related to users/tenants/claims to put you in the picture.
I have a table that creates a relationship between users and tenants (Users_Tenants). This is a many to many relationship.A user can belong to many tenants and a tenant can have many users.
On the other hand, I have a well defined set of User Claims defining permissions like can_list_x, can_delete_x, can_edit_x etc. I would like these claims to be stored in a class inherited from IdentityUserClaim and seeded in the initial migration, this table could be called (ApplicationUserClaim)
And lastly I will have a table that creates a relationship between User_Tenants and ApplicationUserClaim (Claims_UserTenants). That builds the relation among a User,Tenant pair and a claim assigned to it. Again it is a Many to Many relationship.
As you can see, In my design I'm not talking about roles anywhere. And this is how I want it to be. So, my DBContext inherits from IdentityUserContext instead of IdentityDBContext. I inherit it passing my ApplicationUser and ApplicationUserClaim to the list of needed generics:
public class ApplicationDbContext : IdentityUserContext<ApplicationUser,string, ApplicationUserClaim, IdentityUserLogin<string>, IdentityUserToken<string>>
{
}
One of the main problems is that when I update my databse from migration, The ApplicationUserClaim has a field called UserId that I don't want because the relationship is created now with the Claims_UserTenants table.
So my questions are:
1- Is it possible to remove this field? I tried::
modelBuilder.Entity<ApplicationUserClaim>().Ignore(o => o.UserId);
but it did not worked.
2- Can Identity Core be modified to accomodate my db design? Or is it better to ditch it and create my own system? I hope I don't have to do this because identity system provides a lot of value built-in...
Cheers!