Error Message : The entity type IdentityRole is not part of the model for the current context
the above Error show when access to this code
if (!roleManager.RoleExists("MasterAdmin"))
my codes are placed in Startup File as the below :
- public void CreateDefaultRolesAndUsers()
- {
- var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(db));
- var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
- IdentityRole role = new IdentityRole();
- if (!roleManager.RoleExists("MasterAdmin"))
- {
- role.Name = "MasterAdmin";
- roleManager.Create(role);
- ApplicationUser user = new ApplicationUser();
- user.UserName = "enmaMasterAdmin";
- user.Email = "[email protected]";
-
- var check = userManager.Create(user,"Master/77777777");
- if (check.Succeeded)
- {
- userManager.AddToRole(user.Id, "MasterAdmin");
- }
-
- }
-
- }
Note \ I use Database First Approach