Petar Bechev
Petar Bechev

Reputation: 607

The entity type IdentityUser is not part of the model for the current context in ASP.NET Identity

I want to check if there is a user with particular username and password in ASP.NET Identity. I tried and that is my code:

UserManager<IdentityUser> userManager = new UserManager<IdentityUser>(new UserStore<IdentityUser>(new ApplicationDbContext()));
var user = await userManager.FindAsync(userName, password);

However, something goes wrong and that is the error:

The entity type IdentityUser is not part of the model for the current context.

Would you tell me a solution?

Upvotes: 1

Views: 1576

Answers (1)

Abdul Hadi
Abdul Hadi

Reputation: 1228

If you are using default MVC project you have to use ApplicationUser model instead of IdentityUser and update your code as follow:

  public async Task<ViewResult> Index()
    {
        UserManager<ApplicationUser> userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
        var user = await userManager.FindAsync("UserName", "Password");
        return View(user);
    }

Upvotes: 2

Related Questions