Я попытался добавить идентификатор ASP.NET к существующему проекту MVC 5. Я применил некоторые статьи об этой проблеме.my.Models.IdentityUserLogin:: EntityType 'IdentityUserLogin' не имеет ключа
Я следовал этой статьи: Adding ASP.NET MVC5 Identity Authentication to an existing project http://www.yagizhanpala.com/asp_net_identity_ile_mvc_projede_uyelik_islemleri/
Но после реализации, у меня была такая же проблема.
my.Models.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.
my.Models.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType.
IdentityUserLogins: EntityType: EntitySet 'IdentityUserLogins' is based on type 'IdentityUserLogin' that has no keys defined.
IdentityUserRoles: EntityType: EntitySet 'IdentityUserRoles' is based on type 'IdentityUserRole' that has no keys defined.
Примечание: Для создания класса модели я использую инженер обратного кода.
public class ApplicationRole : IdentityRole
{
public string Description { get; set; }
public ApplicationRole() { }
public ApplicationRole(string roleName, string description) : base(roleName)
{
this.Description = description;
}
}
public class ApplicationUser : IdentityUser
{
public string Name { get; set; }
public string Surname { get; set; }
}
OnModelcreating()
метод включает в себя:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new LoginMap());
modelBuilder.Configurations.Add(new RegisterMap());
}
Это звучит как ваши модели идентичности, не унаследовав от правильных базовых классов (например, из связанного вопроса: 'общественного класса AppRole: IdentityRole {... } '). –
Не могли бы вы представить свой код классов 'User' и' Role'? –
** public class ApplicationRole: IdentityRole { public string Описание {get; задавать; } общественного ApplicationRole() {} общественных ApplicationRole (строка RoleName, строка описания) : основание (RoleName) { this.Description = описание; } } ** – user3824679