c# - RoleManager working but UserManager gives "The entity type IdentityUser is not part of the model for the current context." error -


i'm building mvc 5 app using ef6 code first , running issue while trying build basic user management interfaces. error i'm receiving "the entity type identityuser not part of model current context".

the code:

service layer:

public class coreservice {     private iprincipal user;     private identitydb identdb;     private coredb coredb;     private rolemanager<identityrole> _rolemanager;     private usermanager<identityuser> _usermanager;      public coreservice()     {         user = httpcontext.current.user;         identdb = new identitydb();         coredb = new coredb();         _rolemanager = new rolemanager<identityrole>(new rolestore<identityrole>(identdb));         _usermanager = new usermanager<identityuser>(new userstore<identityuser>(identdb));     }      public void testidentitymanagers(string rolename, string username)     {         var role = _rolemanager.findbyname(rolename);         var user = _usermanager.findbyname(username);     } } 

database context:

public class identitydb : identitydbcontext<applicationuser> {     public identitydb()         : base("defaultconnection", throwifv1schema: false)     {     }      public static identitydb create()     {         return new identitydb();     } } 

my app has no trouble using _rolemanager add, delete , otherwise manipulate roles know database connection string working.

i'm pretty new ef6 code first , identity 2.0 i'm sure i'm missing here.

the immediate use need _usermanagement access .getroles(userid) method. i've written work around data using:

list<string> rolesmemberof = (from x in identdb.users.where(x => x.id == userid).firstordefault().roles.select(x => x.roleid)                                      join y in _rolemanager.roles on x equals y.id                                      select y.name).tolist(); 

however seems cleaner , easier if can fix usermanager.

edit:

it looks changing:

_usermanager = new usermanager<identityuser>(new userstore<identityuser>(identdb)); 

to:

_usermanager = new applicationusermanager(new userstore<applicationuser>(identdb)); 

is working now. i'm still unclear why identityuser wasn't working or differences has versus applicationuser.

it looks changing:

_usermanager = new usermanager<identityuser>(new userstore<identityuser>(identdb)); 

to:

_usermanager = new applicationusermanager(new userstore<applicationuser>(identdb)); 

is working now. i'm still unclear why identityuser wasn't working or differences has versus applicationuser.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -