Abdulmajeed Alshari

Abdulmajeed Alshari

  • NA
  • 266
  • 60.7k

The entity type IdentityRole is not part of the model

Oct 5 2018 11:53 AM
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 :
 
  1. public void CreateDefaultRolesAndUsers()  
  2.         {  
  3.             var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(db));  
  4.             var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));  
  5.             IdentityRole role = new IdentityRole();  
  6.             if (!roleManager.RoleExists("MasterAdmin"))  
  7.             {  
  8.                 role.Name = "MasterAdmin";  
  9.                 roleManager.Create(role);  
  10.                 ApplicationUser user = new ApplicationUser();  
  11.                 user.UserName = "enmaMasterAdmin";  
  12.                 user.Email = "[email protected]";  
  13.   
  14.                 var check = userManager.Create(user,"Master/77777777");  
  15.                 if (check.Succeeded)  
  16.                 {  
  17.                     userManager.AddToRole(user.Id, "MasterAdmin");  
  18.                 }  
  19.   
  20.             }  
  21.   
  22.         }  
Note \ I use Database First Approach