Android Azure 移动服务离线同步软删除

Android Azure Mobile Services Offline Sync Soft Delete

我已经实现了一个支持 Azure 移动服务和离线同步的 Android 应用程序。我一直在用两种不同的设备对其进行测试。我在第一台设备上执行了删除操作(软删除),并且工作正常。然后我让它同步,检查服务器端记录,已删除列有 'true' 标记它做了什么。但我似乎无法让第二个 tablet 同步以反映新的更改,即不显示已删除的记录。

为了启用软删除,我已将 enableSoftDelete: true 添加到 Azure 上应用服务的 table 控制器中。我没有在删除过程方面触及我的应用程序,但下面是一个典型的删除过程:

    Save save = getSave(SaveID);
try {
            mtblSave.delete(save);
            return true;

        } catch (Exception exception) {
            exception.printStackTrace();
            return false;
        }

我在 Azure SQL 服务器上使用 .NET 后端。

有什么想法吗?

提前致谢

But I cannot seem to get the second tablet to sync to reflect the new changes i.e. do not display the deleted record.

Using soft delete in Mobile Services所述如下:

When using the Offline data Sync for Mobile Services feature, the client SDK automatically queries for deleted records and removes them from the local database. Without soft delete enabled, you need to write additional code on the backend so that the client SDK knows which records to remove from the local store. Otherwise, the client local store and backend will be inconsistent with regard to these deleted records and the client method PurgeAsync() must be called to clear the local store.

我假设您在构造查询以提取数据时可以利用 fiddler to capture the network traces when handling pull operation. Also, you could add includeDeleted 方法,如下所示,以便更好地理解此功能。

var pullQuery = mClient.getTable(ToDoItem.class).where().field("complete").eq(false).includeDeleted();
mToDoTable.pull(mPullQuery).get();

此外,关于在移动服务中使用离线数据同步的详细信息,您可以参考here

更新:

查询参数是用于筛选结果的可选查询。

正如How offline synchronization works提到的关于增量同步

If you use a non-null queryId, the Azure Mobile SDK performs an incremental sync. Each time a pull operation returns a set of results, the latest updatedAt timestamp from that result set is stored in the SDK local system tables. Subsequent pull operations retrieve only records after that timestamp.

The query name can be any string you choose, but it must be unique for each logical query in your app. Otherwise, different pull operations could overwrite the same incremental sync timestamp and your queries can return incorrect results.

您可以参考此 answer 并解决您的问题。