Reputation: 11
I wanted to run an async method in asp.net core stat up file but it make an error
here it is the my code:
initialRoles(roleManager, userManager).Wait();
and method is :
private async Task initialRoles(RoleManager<IdentityRole> roleManager, UserManager<ApplicationUser> userManager)
{
IdentityRole identityRole = await roleManager.FindByNameAsync("admin");
if (identityRole == null)
{
identityRole = new IdentityRole("admin");
await roleManager.CreateAsync(identityRole);
}
}
and error is :"An error occurred while updating the entries"
Upvotes: 1
Views: 67
Reputation: 551
You can create role by writing below code. In your code, you are passing role name in IdentityRole object.
var role = new IdentityRole();
role.Name = "admin";
await roleManager.CreateAsync(role);
Pls upvote if it helps.
Upvotes: 1