首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Azure移动服务- IMobileServiceSyncTable PullAsync不填充本地同步表

问Azure移动服务- IMobileServiceSyncTable PullAsync不填充本地同步表
EN

Stack Overflow用户
提问于 2017-12-10 20:57:39
回答 1查看 243关注 0票数 0

我正在为我的Xamarin.iOS应用程序与Azure移动服务公司合作。我已经在后端和客户端设置了我的respective,我能够成功地在我的应用程序上注册一个帐户,并在后端的相应表中看到条目。

但是,当我使用对PullAsync的调用填充本地同步表时,同步表始终是空的,即使我试图返回该表中的所有记录,而无需在查询中使用任何筛选器。

我不知道为什么PullAsync不填充我的同步表,即使没有异常。

下面是我的代码:

初始化本地存储

代码语言:javascript
复制
public class AzureMobileClientServiceDataManager : IAzureMobileClientServiceDataManager, IMobileServiceSyncHandler
{

    const string localDbPath = "sample.db";
    MobileServiceSQLiteStore store;

    MobileServiceClient client { get; set; }

    public AzureMobileClientServiceDataManager(IAzureMobileClientService azureMobileClientService)
    {
        CurrentPlatform.Init();

        SQLitePCL.CurrentPlatform.Init();

        //Initialize the Mobile service client with the Mobile App URL,Gatewaty URL and Key
        client = azureMobileClientService.GetMobileServiceClientInstance();
    }

    public async Task InitializeStoreAsync()
    {
        store = new MobileServiceSQLiteStore(localDbPath);
        store.DefineTable<Account>();
        store.DefineTable<UserProfile>();
        store.DefineTable<Purchase>();

        await client.SyncContext.InitializeAsync(store, this);

    }

    public MobileServiceClient GetInstance()
    {
        return client;
    }

    public Task OnPushCompleteAsync(MobileServicePushCompletionResult result)
    {
        foreach (var error in result.Errors)
        {
            Console.WriteLine("Error :" + error.RawResult);
        }

        return Task.FromResult(0);
    }

    public Task<JObject> ExecuteTableOperationAsync(IMobileServiceTableOperation operation)
    {
        return operation.ExecuteAsync();
    }
}

public interface IAzureMobileClientServiceDataManager
{
    Task InitializeStoreAsync();

    MobileServiceClient GetInstance();

}

在一个新用户成功注册之后,我调用这个函数来填充我的表。

代码语言:javascript
复制
public async Task<Result<bool>> PopulateData()
    {
       try{

       await accountTable.PullAsync("localAccount", accountTable.Where(ac => ac.Id == mobileServiceClient.CurrentUser.UserId));
       await userProfileTable.PullAsync("localUserProfile", userProfileTable.Where(up => up.AccountId == mobileServiceClient.CurrentUser.UserId));


      return Result<bool>.Success(true);

    }catch(Exception ex)
        {
            return Result<bool>.Failure(ex, ex.StackTrace);
        }

   }
EN

回答 1

Stack Overflow用户

发布于 2017-12-11 15:29:04

每张桌子有一张“无菌表”吗?如果是这样,你就会遇到麻烦。MobileServiceClient意味着是全局的,您将遇到多个表的问题,因为每次都要重新初始化该表。

另外,尝试将日志记录SQLite存储添加到应用程序中,它将记录所有本地数据库语句,下面是一个示例:https://github.com/Azure-Samples/app-service-mobile-dotnet-todo-list-files/blob/master/src/client/MobileAppsFilesSample/Helpers/LoggingHandler.cs

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47743383

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档