How to handle pagination with IMobileServiceSyncTable and Azure Mobile Services

Viewed 1091

How do you paginate data returning from the IMobileServiceSyncTable<T>.PullAsync() method?

I've tried doing something like this, but it's not working how I expected:

myTable is a IMobileServiceTable<T>

mySyncTable is a IMobileServiceSyncTable<T>

// Already tracking how many records exist
// Note* Not using the sync table here, because that was not getting the correct results. 
// It seemed more correct to use the regular table so it was "live" data.
var totalCount = myTable.Take(0).IncludeTotalCount().ToListAsync();

// Try and sync a "page" of data, limited by the values here
var query = mySyncTable.Skip(count).Take(maxPerPage);
await mySyncTable.PullAsync(null, query);

// At this point, I expect the local store to have a set of data
// So I try and get that "page" of data
var results = await mySyncTable.ReadAsync(query);

// That returns 0 results, so I tried
var results = await mySyncTable.Skip(count).Take(maxPerPage).ToEnumerableAsync();

// Still 0 results, so just give me all the things
var results = await mySyncTable.ToEnumerableAsync();

// Still 0...

I am getting totalCount greater than 0, but when I think I am reading from the local store, I can't seem to get results back with Skip and Take. Please suggest how to properly paginate data from a sync table.

2 Answers
Related