How can I rename these table:AspnetUser,AspnetRole,AspNetUserRole in asp.net core 1.0?
any advice will be appreciative.
You can probably override them in your IdentityContext with the OnModelCreating method.
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
builder.Entity<IdentityUser>().ToTable("YourTableName");
}
Thanks for your response. I tried it. Table AspnetUser and AspnetRole are ok . But AspNetUserRole can not.
public class Comm_role : IdentityRole〈string〉
public class Comm_roleclaim : IdentityRoleClaim〈string〉
public class Comm_user : IdentityUser〈string〉
public class Comm_userrole : IdentityUserRole〈string〉
public class Comm_userclaim : IdentityUserClaim〈string〉
public class Comm_userlogin : IdentityUserLogin〈string〉
public class Comm_usertoken : IdentityUserToken〈string〉
and
public class RichErpDbContext : IdentityDbContext 〈Comm_user, Comm_role, string〉
...
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity〈Comm_role〉(entity =>
{
entity.ToTable(name: "comm_role");
});
builder.Entity〈Comm_roleclaim〉(entity =>
{
entity.ToTable("comm_roleclaim");
});
builder.Entity〈Comm_user〉(entity =>
{
entity.ToTable(name: "comm_user");
});
builder.Entity〈Comm_userrole〉(entity =>
{
entity.ToTable(name: "comm_userrole");
});
......
}
Table AspnetUser and AspnetRole are ok . But AspNetUserRole can not be renamed.
How to notice Asp.net Core using Comm_userrole but not AspNetUserRole ???
Try
builder.Entity<Comm_role>().ToTable("Comm_role");
builder.Entity<Comm_roleclaim>().ToTable("Comm_roleclaim");
builder.Entity<Comm_user>().ToTable("Comm_user);
builder.Entity<Comm_userrole>().ToTable("Comm_userrole);
builder.Entity<Comm_userclaim>().ToTable("Comm_userclaim);
builder.Entity<Comm_userlogin>().ToTable("Comm_userlogin);
builder.Entity<Comm_usertoken>().ToTable("Comm_usertoken);
yes,I did so. Table AspnetUser and AspnetRole are ok . But AspNetUserRole can not be renamed.
I think because Asp.net Core didnot recognize Comm_userrole .
in public class RichErpDbContext : IdentityDbContext 〈Comm_user, Comm_role, string〉
it has table Comm_user and Comm_role , it has not Comm_userrole etc.
If all you want to do is rename the entities, you don't have to create new entity types. ToTable should work fine against the default entities.
Once you start plugging in custom entities, you will need to drop down below the sugar and register your stores differently.
public class ApplicationDbContext : IdentityDbContext<MyUser, IdentityRole<string, MyUserRole, IdentityRoleClaim<string>>, string, MyUserClaim, MyUserRole, MyUserLogin, IdentityRoleClaim<string>, MyUserToken>
In startup: instead of AddEntityFrameworkStores you will need something like this instead:
.AddUserStore<UserStore<MyUser, IdentityRole<string, MyUserRole, IdentityRoleClaim<string>>, ApplicationDbContext, string, MyUserClaim, MyUserRole, MyUserLogin, MyUserToken>>();
Try
builder.Entity<ApplicationUser>().ToTable("User");
builder.Entity<ApplicationRole>().ToTable("Role");
builder.Entity<IdentityUserRole<string>>().ToTable("UserRole");
builder.Entity<IdentityUserClaim<string>>().ToTable("UserClaim");
builder.Entity<IdentityUserLogin<string>>().ToTable("UserLogin");
builder.Entity<IdentityRoleClaim<string>>().ToTable("RoleClaim");
builder.Entity<IdentityUserToken<string>>().ToTable("UserToken");
how to do this in custom classes in core 2.0