我想循环遍历一个结果集,运行一个查询来检索数据,然后将该数据添加到列表中并将其返回。异步返回对象列表
的问题是,我试图以异步方式做到这一点,我得到的错误:
'System.Collections.Generic.List' does not contain a definition for 'ToListAsync' and the best extension method overload 'System.Data.Entity.QueryableExtensions.ToListAsync(System.Linq.IQueryable)' has some invalid arguments
下面是方法的代码:
public async Task<List<IHFData>> GetHFServiceData(string wtTransfereeId)
{
var hfDataList = new List<HFData>();
Parallel.ForEach(aauthorizationList, item =>
{
// code to retrieve data from database (truncated)
HFData hfData = Db.hfAuthorizations.AsNoTracking()....SingleOrDefault();
hfDataList.Add(hfData);
}
return await hfDataList.ToListAsync(); // errors on this line
}
如何建立和回报我的列表异步?
似乎'ToListAsync'是[实体框架方法(http://msdn.microsoft .com/en-us/library/dn220261(v = vs.113).aspx) – gunr2171 2014-09-26 18:03:23