脚手架应用用户

问题描述 投票:0回答:2

我正在使用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; }

我知道这是错的,但我不知道如何解决这个问题。

asp.net-mvc-5 entity-framework-6
2个回答
1
投票

这些步骤让我成功地构建了ApplicationUser。

  1. 将ApplicationUser的名字重构为其他名字,比如MyAppUser,
  2. 用EntityFramework添加Controller,使用MyappUser模型,这样就可以成功地对MyAppUser进行脚手架。
  3. 脚手架将创造财产 DbSet<MyAppUser> MyAppUsers 对于ApplicationDbContext,删除它
  4. 在新创建的控制器中,改变所有出现的 db.MyAppUsersdb.Users

那你就可以了,希望对你有所帮助。


1
投票

以下是我的步骤,如果你想管理 AspNetUsers 表,当您启用迁移时,所有的默认设置都已到位。

  • 首先使用带有视图的MVC 5 Controller创建控制器,使用EFL

enter image description here

  • 添加你的控制器,并进行以下设置。Async不是一个选项,因为Users DBSet不支持async,除非我们将使用UserManager。这将是一个不同的主题。

enter image description here

  • 转到生成的控制器,并重命名所有控制器的实例。ApplicationUsersUsers

enter image description here

  • 最后,您现在可以安全地删除 ApplicationUsers 关于 IdentityModel (我的情况是第37行)

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.