Azure Mobile Services PullAsync()不填充同步表

本文关键字:填充 同步 Mobile Services PullAsync Azure | 更新日期: 2023-09-27 18:13:52

所以我有一个名为Profile的远程表,它已经创建了多个条目。现在我正在尝试将离线功能集成到我的应用程序中。到目前为止,我在我的代码中遇到了PushAsyncPullAsync方法的问题。

我希望能够通过调用PullAsync将远程表中的所有数据复制到本地表,尽管它不会抛出任何异常,但也不会填充我的表。以下是我的意思。

        var db = new SQLiteConnection("syncstoreTEMP.db");
        var store = new MobileServiceSQLiteStore("syncstoreTEMP.db");
        store.DefineTable<Profile>();
        MobileService.SyncContext.InitializeAsync(store).Wait();
        var remoteValues = MobileService.GetTable<Profile>()
            .ToListAsync()
            .Result;
        MobileService.GetSyncTable<Profile>()
            .PullAsync(null, MobileService.GetSyncTable<Profile>().CreateQuery())
            .Wait();
        var localValues = MobileService.GetSyncTable<Profile>()
            .ToListAsync()
            .Result;

当我运行这段代码时,remoteValues的总长度为5,但是localValues即使在发出来自远程的Pull之后仍然显示0项。如何使同步表与远程表匹配?

Azure Mobile Services PullAsync()不填充同步表

奇怪的是,您没有得到任何异常,但您似乎正在创建到本地商店的两个连接。你应该有新的SQLiteConnection,只有行创建MobileServiceSQLiteStore。

下面是一个指导如何设置的教程:https://azure.microsoft.com/en-us/documentation/articles/mobile-services-xamarin-ios-get-started-offline-data/

我还建议你在你的MobileServiceClient中添加一个DelegatingHandler来记录所有的请求和响应。然后你就能清楚地看到哪里出了问题。下面的示例显示了这一点,并且还包括SQLite存储的日志扩展,以便您可以准确地看到本地发生的事情:https://github.com/paulbatum/FieldEngineerLite/blob/master/FieldEngineerLite.Client/FieldEngineerLite/Helpers/LoggingHelpers.cs