1

I'm creating MVC application, trying to get records out of database using CRUD, but then I get this error

"Multiple object sets per type are not supported. The object sets 'ApplicationUsers' and 'Users' can both contain instances of type 'WebApplication1.Models.ApplicationUser'."

I can't find "Users" property used anywhere, and when I replace all "ApplicationUser" with "User", I get this error:

"Multiple object sets per type are not supported. The object sets 'Users' and 'Users' can both contain instances of type 'WebApplication1.Models.ApplicationUser'."

I'm stuck and I have no idea what to do...

Edit:

    namespace WebApplication1.Models
{
    // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
    public class ApplicationUser : IdentityUser
    {

        public string Name { get; set; }
        public string DoB { get; set; }
        public string Additional { get; set; }


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

        public System.Data.Entity.DbSet<WebApplication1.Models.ApplicationUser> ApplicationUser { get; set; }
    }
odinas1212
  • 71
  • 2
  • 14

1 Answers1

1

Just remove this line:

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

Because when you inherit from IdentityDbContext<ApplicationUser> your class already have property DbSet<T> Users where T is class specified by you (ApplicationUser)

Edit: For now to access users dbset use dbContext.Users.

If you want to use dbContext.ApplicationUser create wrapper property in ApplicationDbContext:

public DbSet<ApplicationUser> ApplicationUser
{
  get { return Users; }
  set { Users = value; } 
}
Denis Krasakov
  • 1,498
  • 2
  • 13
  • 17
  • After removing the said line, im getting 7 errors like `CS1061 'ApplicationDbContext' does not contain a definition for 'ApplicationUser' and no extension method 'ApplicationUser' accepting a first argument of type 'ApplicationDbContext' could be found (are you missing a using directive or an assembly reference?) ` – odinas1212 Apr 01 '17 at 19:28