使用以下代码:
public static async Task<List<DUCKBILLED_PLATYPI>> GetLocationsForPlatypiAndTimeRange(HashSet<string> PlatypiIds, DateTime EarliestToShow, DateTime LatestToShow)
{
List<DUCKBILLED_PLATYPI> listLocs = new List<DUCKBILLED_PLATYPI>();
List<string> PlatypusBillIDList;
string PlatypusBillID;
IMobileServiceTable<DUCKBILLED_PLATYPI> table = App.MobileService.GetTable<DUCKBILLED_PLATYPI>();
MobileServiceTableQuery<DUCKBILLED_PLATYPI> query;
foreach (var item in PlatypiIds)
{
PlatypusBillIDList = await GetPlatypusBillIDForPlatypusID(item);
PlatypusBillID = PlatypusBillIDList[0];
query =
table.Where(l => l.PlatypusBillID == PlatypusBillID).
Where(l => l.UpdateTimeUTC >= EarliestToShow).
Where(l => l.UpdateTimeUTC <= LatestToShow).
OrderBy(l => l.UpdateTimeUTC);
listLocs.Add(query);
}
return listLocs;
}
。我在同一行收到两条错误消息("listLocs.Add(query);"行);它们是:
1) Error 1 The best overloaded method match for 'System.Collections.Generic.List<MetroSandboxPlaypen.TaSLs_Data.DUCKBILLED_PLATYPI>.Add(MetroSandboxPlaypen.TaSLs_Data.DUCKBILLED_PLATYPI)' has some invalid arguments
2) Error 2 Argument 1: cannot convert from 'Microsoft.WindowsAzure.MobileServices.MobileServiceTableQuery<MetroSandboxPlaypen.TaSLs_Data.DUCKBILLED_PLATYPI>' to 'MetroSandboxPlaypen.TaSLs_Data.DUCKBILLED_PLATYPI'
你还没有执行查询;你需要具体化它:等待查询。ToListAsync 或 await query。ToEnumerableAsync. 您还需要使用 listLocs.AddRange 与 Add
,因为您可能会返回 0、1 或多行。
另一方面,您期望PlatypiIds
多少项?您的循环看起来至少为每个项目进行了两次服务调用,因此您可能需要测试聊天是否对最终用户体验有影响,而是尝试通过一两个查询来获取所有数据。