Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Identity 2 UserManager get all users async

Can somebody tell if there is a way to get all users async in ASP.NET Identity 2?

In the UserManager.Users there is nothing async or find all async or somwething like that

like image 954
David Dury Avatar asked Oct 14 '14 09:10

David Dury


1 Answers

There is no way to do this asynchronously with the UserManager class directly. You can either wrap it in your own asynchronous method: (this might be a bit evil)

public async Task<IQueryable<User>> GetUsersAsync {     return await Task.Run(() =>     {         return userManager.Users();      } } 

Or use the ToListAsync extension method:

public async Task<List<User>> GetUsersAsync() {     using (var context = new YourContext())     {         return await UserManager.Users.ToListAsync();     } } 

Or use your context directly:

public async Task<List<User>> GetUsersAsync() {     using (var context = new YourContext())     {         return await context.Users.ToListAsync();     } } 
like image 165
DavidG Avatar answered Sep 19 '22 21:09

DavidG