简体   繁体   中英

Azure MobileService Client - ToListAsync not retrieving all data

I am using the MobileServiceClient class provided by Azure to fetch data from my Azure SQL database . It appears that I am only getting the first 60 or so rows from my database when I use the ToListAsync() function. Is there a way around this?

List<riskregister_hazard_template> categories;

categories = await riskTable.Where(r => r.level_1 == _level1)
.Where(r => r.level_2 == _level2).ToListAsync();

Please read the following excerpt:

By default, a read operation in a table controller will return up to 50 items. If we have more in our table storage, then the client will need to request more, by casting the result of the ToListAsync or ToEnumerableAsync methods to the IQueryResultEnumerable interface. The code below shows how to go through all elements in the table.

 public async Task<double> CalculateAverageAge()
{
    var client = new MobileServiceClient(AppUrl, AppKey);
    var table = client.GetTable<Person>();
    var sum = 0.0;
    var count = 0;
    var items = await table.Take(10).ToEnumerableAsync();
    while (items != null && items.Count() != 0)
    {
        count += items.Count();
        sum += Enumerable.Sum(items, i => i.Age);

        var queryResult = items as IQueryResultEnumerable<Person>;
        if (queryResult != null && queryResult.NextLink != null)
        {
            items = await table.ReadAsync<Person>(queryResult.NextLink);
        }
        else
        {
            items = null;
        }
    }

    return sum / count;
}

Source: https://azure.microsoft.com/en-us/blog/better-support-for-paging-with-table-storage-in-azure-mobile-services-net-backend/

Hope this helps.

Regards,

Alberto Morillo

SQLCoffee.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM