问题描述
i
create asp.net identity application in this application i used custom class Name Called ApplicationRole and That class is inherited with IdentityRole
public class ApplicationRole:IdentityRole
{
public ApplicationRole():base() { }
public bool IsSuperAdmin { get; set; }
}
and then i used this class on the <pre lang="C#">OnModelCreating Method</pre>
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUser>().ToTable("tblUser").Property(x => x.Id).HasColumnName("UserID");
modelBuilder.Entity<ApplicationRole>().ToTable("tblRoles").Property(x => x.Id).HasColumnName("RoleID");
modelBuilder.Entity<IdentityUserRole>().ToTable("tblUserRole").Property(x => x.RoleId).HasColumnName("RoleID");
modelBuilder.Entity<IdentityUserRole>().ToTable("tblUserRole").Property(x => x.UserId).HasColumnName("UserID");
modelBuilder.Entity<IdentityUserClaim>().ToTable("tblUserClaim").Property(x => x.Id).HasColumnName("ClaimID");
modelBuilder.Entity<IdentityUserLogin>().ToTable("tblUserLogin");
}
after this i used Add-migrations and then update-DataBase
now i opened sql Server it will create aspnetRole table extra
我尝试过:
公共类ApplicationRole:IdentityRole
{
public ApplicationRole():base(){}
public虚拟Office OfficeID {get;组; }
public bool IsSuperAdmin {get;组; }
}
公共类办公室
{
[Key]
public long OfficeID {get;组; }
公共字符串OfficeName {get;组; }
公共虚拟ICollection< applicationuser>用户{get;组; }
public virtual ICollection< applicationrole>角色{get;组; }
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity< ApplicationUser>()。ToTable (用户)。属性(x => x.Id).HasColumnName(UserID);
modelBuilder.Entity< IdentityUserRole>()。ToTable(UserRole);
modelBuilder.Entity< IdentityUserClaim>()。ToTable(UserClaims)。Property(x => x.Id).HasColumnName(ClaimID);
modelBuilder。实体< IdentityUserLogin>()。ToTable(UserLogin);
modelBuilder.Entity< ApplicationRole>()。ToTable(Roles)。Property(x => x.Id).HasColumnName (RoleID);
}
What I have tried:
public class ApplicationRole : IdentityRole
{
public ApplicationRole() : base() { }
public virtual Office OfficeID { get; set; }
public bool IsSuperAdmin { get; set; }
}
public class Office
{
[Key]
public long OfficeID { get; set; }
public string OfficeName { get; set; }
public virtual ICollection<applicationuser> User { get; set; }
public virtual ICollection<applicationrole> Role { get; set; }
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUser>().ToTable("User").Property(x => x.Id).HasColumnName("UserID");
modelBuilder.Entity<IdentityUserRole>().ToTable("UserRole");
modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims").Property(x => x.Id).HasColumnName("ClaimID");
modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogin");
modelBuilder.Entity<ApplicationRole>().ToTable("Roles").Property(x => x.Id).HasColumnName("RoleID");
}
推荐答案
这篇关于我的应用程序我使用的是ASP身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!