如何从 IdentityUserLogin 和 IdentityUserRole 继承 asp.net mvc



>我有两个类,它们是名称tblUserProfile和tblUserRole 我想向我自己的类添加多个属性,mentioned.in 事实上,tblUserProfile使用tblUserProfile:IdentityUserLogin和tblUserRole使用tblAccessRole : IdentityUserRole但是当我进行添加迁移时,它确实给了我此错误EntityType has no key defined. Define the key for this EntityType之后我添加了键属性,然后 EF 确实向我展示了Column names in each table must be unique. Column name 'RoleId' in table 'tblAccessRoles' is specified more than once.请告诉我如何解决它。

   public class tblUserProfile : IdentityUserLogin
    {
        public int UserID { get; set; }
        public string NameFamily { get; set; }
    }
  public class tblAccessRole : IdentityUserRole
    {
        public int RoleID { get; set; }
        public string  Section { get; set; }
        public bool IsSave { get; set; }
    }

tblUserProfile中删除UserID RoleID,从tblAccessRole

在您的数据库上下文中添加:

  protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
      modelBuilder.Entity<tblUserProfile>()//IdentityUserLogin
            .HasKey(l => new { l.LoginProvider, l.ProviderKey, l.UserId })
            .ToTable("tblUserProfile");// Database Table Nam    
            modelBuilder.Entity<tblAccessRole>()//IdentityUserRole
            .HasKey(r => new { r.UserId, r.RoleId })
                .ToTable("tblAccessRole");// Database Table Name
    }

相关内容

  • 没有找到相关文章