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

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

Accepted Answer

Make sure you explicitly mention the custom user class type when utilizing a custom user class with ASP.NET Identity.<T> the to bothUserManager both theUserStore after instantiation.

private UserManager<UserModel> _userManager;

public AccountController()
{
    AuthContext _ctx = new AuthContext();

    UserStore<UserModel> userStore = new UserStore<UserModel>(_ctx);
    _userManager = new UserManager<UserModel>(userStore);     
}

or, in brevity (like your comment in response),

private UserManager<UserModel> _userManager;

public AccountController()
{
    AuthContext _ctx = new AuthContext();    
    _userManager = new UserManager<UserModel>(new UserStore<UserModel>(_ctx));     
}

If the type is permitted to be set to default,IdentityUser You will encounter the issue you mentioned when attempting to utilize a custom class.

19
10/8/2014 12:45:55 AM

Popular Answer

I was experiencing the same issue and I recall encountering a related issue while using SimpleMembership in MVC4.

I have an EDMX file because I'm developing databases first. It turns out that the connection string generated when you produce your.edmx model file is disliked by ASP.NET Identity. This issue is most likely to occur if you are using an EDM connection string in:base(oeEDMConnString).

It worked after I created a standard connection string called in:base that referred to the database containing the ASP.NET Identity tables (in my instance, the same database).

comparable to this

<add name="IdentityConnection" connectionString="data source=THEJUS\SQLSERVER2014;initial catalog=IdentitySample;integrated security=True;MultipleActiveResultSets=True;App=IdentitySample.Admin" providerName="System.Data.SqlClient" />


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