【发布时间】:2014-12-08 17:11:40
【问题描述】:
我正在使用带有 EF 6 的 ASP.NET MVC 5 的默认模板。它将身份模型生成为
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
我希望能够管理和编辑用户列表,因此我搭建了身份模型并在 ApplicationDbContext 类中添加了以下行。
public System.Data.Entity.DbSet<QProj.Models.ApplicationUser> ApplicationUsers { get; set; }
我知道这是错误的,但我不确定如何解决。
【问题讨论】:
-
你是新建了
ApplicationUser类,还是继承自IdentityUser? -
@BrendanGreen 从上面的代码可以看出,ApplicationUser 继承自 IdentityUser。
-
那么您是如何“搭建”ApplicationUser 的?由于您的上下文继承自 IdentityDbContext,因此您不需要在您的类中定义的 dbset。
标签: asp.net-mvc-5 entity-framework-6