ASP.NET Identity - Multiple object sets per type are not supported

asp.net asp.net-identity asp.net-mvc c# entity-framework

Question

I got an error using ASP.NET Identity in my app.

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

I saw a few questions about this error in StackOverflow. All indicate on two DbSet objects of the same type. But in my DbContext there aren't the same types of DbSets. Exception is thrown on FindAsync() method during logging in.

if (ModelState.IsValid)
    var user = await UserManager.FindAsync(model.UserName, model.Password);
    if (user != null && user.IsConfirmed)
    {

The problem is I don't have two DbSets of the same type. My Contexts look like this:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DefaultConnection")
    {
    }

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

}

and

public class RecContext : DbContext
{
    public RecContext()
        : base("RecConnection")
    {
        Database.SetInitializer<RecContext>(new DropCreateDatabaseIfModelChanges<RecContext>());
    }

    public DbSet<Recommendation> Recommendations { get; set; }
    public DbSet<Geolocation> Geolocations { get; set; }
    public DbSet<Faq> Faqs { get; set; }
    public DbSet<IndexText> IndexTexts { get; set; }
}

What could cause this problem? Maybe something connected with in-built ASP.NET Identity functionalities? Anyway, what is Users type? I don't have it in my app...

1
52
8/8/2018 12:19:31 PM

Accepted Answer

You do have two DbSets` of the same type.

IdentityDbContext<T> itself contains Users property declared as:

public DbSet<T> Users { get; set; }

You're declaring second one in your class.

102
6/21/2014 3:54:17 PM

Popular Answer

review this file "ApplicationDbContext.cs", remove the line, generated automatically by scaffold last, should be like this:

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


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