Home > Enterprise >  ASP.NET Core Identity will only insert one role
ASP.NET Core Identity will only insert one role

Time:07-29

This is very odd and I'm stumped. I've got some code for setting up my Identity tables with a few default roles.

Here is my code:

var role = new ApplicationRole
{
    Name = "SuperAdmin"
};

await _roleManager.CreateAsync(role);

role = new ApplicationRole
{                
    Name = "User"
};

await _roleManager.CreateAsync(role);

role = new ApplicationRole
{
    Name = "Support"
};

await _roleManager.CreateAsync(role);

It runs fine. Except that only the first SuperAdmin role is created.

Stepping through, the RoleManager<ApplicationRole> never even fires CreateAsync on the latter two.

No exceptions are thrown. I cannot give you a stack trace because there isn't one.

What's going on? Any ideas?

CodePudding user response:

Argh.

It's my own IRoleStore implementation backed with stored procedures and there was a logic error in the sproc. As soon as any Role existed, a row was always returned from CheckRoleExistsAsync.

Nevermind.

  • Related