【发布时间】:2014-05-08 15:06:32
【问题描述】:
有没有一种方法可以在不指定 IdentityUser、IdentityRole 和 IdentityDbContext 中的 TKey string 的情况下创建自定义用户和角色?我问是因为它似乎认为我不再想要自动生成的主键Id,我绝对想要。执行我在下面所做的操作,UserManager.Create(user, password) 将在 Id 上出现 EntityValidationError 失败。
public class ApplicationUser : IdentityUser<string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
[Required]
[StringLength(50)]
public string FirstName { get; set; }
[Required]
[StringLength(50)]
public string LastName { get; set; }
}
public class ApplicationUserLogin : IdentityUserLogin
{
}
public class ApplicationUserClaim : IdentityUserClaim
{
}
public class ApplicationUserRole : IdentityUserRole
{
}
public class ApplicationRole : IdentityRole<string, ApplicationUserRole>
{
[Required]
[StringLength(50)]
public string ProperName { get; set; }
[Required]
public string Description { get; set; }
}
public class MyAppDb : IdentityDbContext<ApplicationUser, ApplicationRole, string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
public MyAppDb()
: base("MyAppDb")
{
}
public static MyAppDb Create()
{
return new MyAppDb();
}
}
【问题讨论】:
标签: asp.net asp.net-mvc entity-framework asp.net-mvc-5 asp.net-identity