我有两个类,他们是名字tblUserProfile和tblUserRole我想在我提到的我自己的类中添加多个属性。事实上,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; }
}
答案 0 :(得分:0)
从UserID
移除tblUserProfile
,从RoleID
移除tblAccessRole
和
在您的DbContext中添加:
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
}