0
我已經使用Identity 2.0創建了MVC 5網站。我正在使用整數作爲主鍵。如何爲繼承IdentityUser的類創建主鍵
當我嘗試創建一個模型的關聯ApplicationUser我得到以下錯誤:
EntityType 'ApplicationUserRole' has no key defined.
什麼我需要做什麼來解決這個錯誤?
IdentityModels.cs
public class ApplicationUserLogin : IdentityUserLogin<int> { }
public class ApplicationUserClaim : IdentityUserClaim<int> { }
public class ApplicationUserRole : IdentityUserRole<int> { }
public class ApplicationRole : IdentityRole<int, ApplicationUserRole>, IRole<int>
{
public string Description { get; set; }
public ApplicationRole() : base() { }
public ApplicationRole(string name) : this()
{
this.Name = name;
}
public ApplicationRole(string name, string description) : this(name)
{
this.Description = description;
}
}
public class ApplicationUser : IdentityUser<int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>, IUser<int>
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser, int> manager)
{
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
return userIdentity;
}
public string FullName { get; set; }
public virtual ICollection<Employee> Employees { get; set; }
}
Employee.cs
public class Employee
{
public int Id { get; set; }
public string Title { get; set; }
public virtual ApplicationUser User { get; set; }
}