0

I have the following code

private readonly RoleManager<IdentityRole> _roleManager;

private async Task DoStuff(MyViewModel viewModel)
{
    var roles =  await _roleManager.Roles;
    var mylist = await _myRepository.SelectAll();
}

however the only method the role manager support is

public virtual IQueryable<TRole> Roles { get; }

and not an async method.

Github reference

resulting in only a _roleManager.Roles.ToList() method and not a ToListAsync()

so I'm forced to change my code to

 var roles =  _roleManager.Roles;

however now it doesn't wait anymore and will cause unexpected behaviour since the method itself is asynchronous.

Question:

Is there anyway I can still use an asynchronous method for the above

dfmetro
  • 4,462
  • 8
  • 39
  • 65

1 Answers1

0

As far as I known async method is not supported to fetch all the roles via the rolemanager.

You can solve it by accessing the roles via the databasecontext:

var roles = await this._context.Roles.ToListAsync();
Wouter
  • 1,293
  • 2
  • 16
  • 34