Multiple object sets per type are not supported.

ASP.NET MVC 5 (EF 6.1.2)

Posted by iks on 2/7/2015 2:45:15 PM

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


Got this error too many times when I was trying making foriegn key with CodeFirst. Tried too many solutions. Also tried Override method in DBContext as following but it won't work:


public class MyDbContext : IdentityDbContext<ApplicationUser>
{
public MyDbContext()
: base("DefaultConnection")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// Change the name of the table to be Users instead of AspNetUsers
modelBuilder.Entity<IdentityUser>()
.ToTable("Users");
modelBuilder.Entity<ApplicationUser>()
.ToTable("Users");
}
public DbSet<MyModel> MyModels { get; set; }
}

 

Then I renamed ApplicationUser with User and got my solution. You can check it on GitHub Solution.

 

 


Comments

Please leave your comment here!