Mobile Services Offline PullAsync only retrieves data where updatedAt date > the latest record

1k views Asked by At

I am using offline data sync in Mobile Services and the following function only retrieves data where UpdatedAt > the largest updatedAt in the userTable:

await userTable.PullAsync(userTable.Where(a => a.UserName == userName));

The first time this function is executed, it retrieves my data correctly. The second time the function executes, whith a different username, it will only retrieve data where UpdatedAt is greater than the greatest UpdatedAt datetime that is already present in my SQLite db. If I change an UpdatedAt field in the backend (by setting it to DateTime.Now), this record is retrieved. Is this by design or am I missing something?

2

There are 2 answers

0
Niels On BEST ANSWER

For anybody else having issues with this: I have started another thread here where you will find the complete answer

Basically what it comes down to is this:

This will retrieve all records from the backend where username is donna:

await itemTable.PullAsync(itemTable.Where(a => a.UserName == "donna"));

This will retrieve all records where username is "donna" the first time, and after that only updated records. (incremental)

await itemTable.PullAsync("itemtabledonna", itemTable.Where(a => a.UserName == "donna"));

The first parameter is the queryKey. This is used to track your requests to the backend. A very important thing to know is that there is a restriction on this queryKey:

^[a-zA-Z][a-zA-Z0-9]{0,24}$

Meaning: alphanumeric characters, max 25 characters long. So no hyphens either (at the time of this writing). If your queryKey does not match this regex, no recrods will be returned. There is currently no exception thrown and no documentation on this.

1
phillipv On

PullAsync() is supposed to use an incremental sync (getting only records what have a newer date than the last record it retrieved) when you pass in a query key. If not, it should execute your query and pull down all matching records.

It sounds like a bug is occurring if you are getting that behavior without passing in a query key.

Also, in the incremental sync case, it is not the latest updated at in the SQLite DB but a cached version from the last time PullAsync() was ran (that was cached under the given query key)

Your updatedAt column also by default will have a trigger that causes its timestamp to update whenever the row is modified, so you shouldn't have to take any additional actions when using incremental sync.

If the above is not what you are seeing, I recommend submitting a github bug against azure-mobile-services so it can be reviewed.