我使用的是带有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; }我知道这是错误的,但我不知道如何解决这个问题。
发布于 2020-06-07 10:45:13
下面是我的步骤,如果您想管理AspNetUsers表,当您启用带有所有默认设置的迁移时,将为您生成该表。

Use async controller actions,因为Users DbSet不支持异步,除非我们使用UserManager。这将是一个不同的话题。

ApplicationUsers的所有实例重命名为Users

IdentityModel上删除IdentityModel(就我的情况而言,它是第37行)

我们需要删除第37行,就像我在最后一张图片中显示的那样,因为当您运行enable-migrations时,它将无法构建。因为IdentityDbContext<T>本身已经包含了Users属性。因此,不需要在ApplicationDbContext类或您为此声明的任何类下添加额外的ApplicationDbContext。顺便说一句,这个属性是在Scaffold ApplicationUser时自动添加的。
发布于 2015-01-31 06:31:06
这些步骤使我成功地搭建了ApplicationUser:
DbSet<MyAppUser> MyAppUsers创建属性ApplicationDbContext,删除它db.MyAppUsers更改为db.Users那你就可以走了,希望这能帮上忙
https://stackoverflow.com/questions/26351822
复制相似问题