Scaffolding ApplicationUser

asp.net-mvc-5 entity-framework-6

Question

I'm using the default template for ASP.NET MVC 5 with EF 6. It generates the Identity model as

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();
    }
}

I would like to be able to manage and edit the list of users, so I scaffolded the identity model and it added the following line in the ApplicationDbContext class.

public System.Data.Entity.DbSet<QProj.Models.ApplicationUser> ApplicationUsers { get; set; }

I know this is wrong, but I'm not sure how to resolve this.

1
0
10/14/2014 2:40:29 AM

Popular Answer

These are steps made me successfully scaffolding ApplicationUser:

  1. Refactor ApplicationUser name to something else, like MyAppUser,
  2. Add Controller with EntityFramework, using model MyappUser, this will successfully scaffolding MyAppUser,
  3. The Scaffolding will create property DbSet<MyAppUser> MyAppUsers for ApplicationDbContext, delete it
  4. In newly created controller, change all occurence of db.MyAppUsersto db.Users

Then you're good to go, hope this helps

1
1/31/2015 6:31:06 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow