Sto ottenendo il seguente errore quando si tenta di utilizzare un async
lambda all'interno IEnumerable.SelectMany
:Come usare lambda async con SelectMany?
var result = myEnumerable.SelectMany(async (c) => await Functions.GetDataAsync(c.Id));
Gli argomenti di tipo per il metodo 'IEnumerable System.Linq.Enumerable.SelectMany (questo IEnumerable, Func>) "non può essere dedotto dall'utilizzo. Prova a specificare gli argomenti di tipo esplicitamente
Dove GetDataAsync
è definito come:
public interface IFunctions {
Task<IEnumerable<DataItem>> GetDataAsync(string itemId);
}
public class Functions : IFunctions {
public async Task<IEnumerable<DataItem>> GetDataAsync(string itemId) {
// return await httpCall();
}
}
Credo perché il mio metodo GetDataAsync
in realtà restituisce un Task<IEnumerable<T>>
. Ma perché funziona Select
, sicuramente dovrebbe generare lo stesso errore?
var result = myEnumerable.Select(async (c) => await Functions.GetDataAsync(c.Id));
C'è un modo per aggirare questo?
può offrire dichiarazione per 'Functions.GetDataAsync'? – Grundy
@Grundy 'Attività>', ma ho aggiunto la dichiarazione completa alla domanda. Dove 'T' è diverso dal tipo di' myEnumerable' –
CodingIntrigue
@HimBromBeere, selezionare return _collection of collection_, ma penso che OP abbia bisogno di una semplice raccolta – Grundy