How do I retrieve data from registered users?

advertisements
 public ActionResult Restaurants()
        {
            var restaurants = _context.ApplicationUsers.ToList();
            return View(restaurants);
        }

I want to extract the the information of registerd users from ASP.NET MVC and list it. But when I executed above code, I get error message of:

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

How can I list the informations of Registered users in ASP.NET MVC 5?


ASP.NET does not allow you to have 2 DbSet<T>'s in the same context with the same entity type. The most likely cause of this error is initializing your DbContext like the following:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public DbSet<ApplicationUser> ApplicationUsers { get; set; }
}

In the above code, ApplicationDbContext already contains a DbSet of type ApplicationUser inherited from IdentityDbContext<ApplicationUser> (which you can access through _context.Users). By manually adding a second DbSet<ApplicationUser>, we are creating 2 sets with the same entity type. Delete the manual DbSet property, and use the inherited Users set instead.