I am trying to use Entity Framework to access the user table entries in ASP.NET Identity and after scaffolding out a new Controller for the ApplicationUser
class with the ApplicationDbContext
for the database context, I get the runtime error
Multiple object sets per type are not supported. The object sets 'ApplicationUsers' and 'Users' can both contain instances of type 'MyApp.Models.ApplicationUser'
Whilst this question has been asked before here and here, the solutions do not work for me, as I will explain below.
In the process of scaffolding out the Controller and View code, Visual Studio also adds the line
public System.Data.Entity.DbSet<MyApp.Models.ApplicationUser> ApplicationUsers { get; set; }
to the ApplicationDbContext
class.
Now, I realise that the problem is that the IdentityDbContext
class from which ApplicationDbContext
inherits also has a DbSet of type ApplicationUser
but removing this line (as suggested in answers here and here) then creates build errors because this property is used in new Controller class. For instance;
namespace MyApp.Controllers
{
public class NewController : Controller
{
private ApplicationDbContext db = new ApplicationDbContext();
// GET: Admin
public ActionResult Index()
{
return View(db.ApplicationUsers.ToList());
}
}
}
I have tried giving both the property and ApplicationUser a different name but I get the same error.
Is there any way of fixing this problem that does not involve deleting the one line?