Question

With this code:

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;
}

...I get two error messages on the same line (the "listLocs.Add(query);" line); They are:

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'
Was it helpful?

Solution

You haven't executed the query; you need to materialize it: await query.ToListAsync or await query.ToEnumerableAsync. You'll also need to use listLocs.AddRange versus Add, since you may get 0, 1 or multiple rows back.

On another note how many items do you expect in PlatypiIds? Your loop looks like it's making at least two service calls for each item, so you may want to test if the chattiness has an impact on end user experience and instead try to grab all the data with one or two queries.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top