MVC5 uses a new Identity System. How can I get all role names?
I try do access it via IdentityStore
but without success.
This is a bit more intuitive
var roles = dbContext.Roles.OrderBy(x => x.Name);
There's currently no way to do enumeration style methods via the identity interfaces, that will be coming in a future update targeting administration scenarios(post 1.0 RTM), so there's no way to enumerate all users or roles via the Identity APIs. That said, you can always drop down to EF or whatever the store implementation is to directly enumerate the roles/users.
I've found that you can use the DbContext
via the IdentityStore
instance and use the well-known method .Set<T>()
.
This works for me:
var identityStore = new IdentityStore();
foreach (var role in identityStore.DbContext.Set<Role>())
{
Debug.WriteLine(role.Name);
}