2014-10-14 16 views

risposta

15

Non v'è alcun modo per farlo in modo asincrono con la classe UserManager direttamente. O si può avvolgere in un proprio metodo asincrono: (questo potrebbe essere un po 'male)

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

o utilizzare il metodo ToListAsync estensione:

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

o utilizzare il contesto direttamente:

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

Perfetto! Mi hai aperto gli occhi! Mi manca un riferimento a 'System.Data.Entity' per ottenere il metodo di estensione' ToListAsync() '. Ottimo, funziona perfettamente ... –

Problemi correlati