我正在为我的Xamarin.iOS应用程序与Azure移动服务公司合作。我已经在后端和客户端设置了我的respective,我能够成功地在我的应用程序上注册一个帐户,并在后端的相应表中看到条目。
但是,当我使用对PullAsync的调用填充本地同步表时,同步表始终是空的,即使我试图返回该表中的所有记录,而无需在查询中使用任何筛选器。
我不知道为什么PullAsync不填充我的同步表,即使没有异常。
下面是我的代码:
初始化本地存储
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();
}在一个新用户成功注册之后,我调用这个函数来填充我的表。
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);
}
}发布于 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
https://stackoverflow.com/questions/47743383
复制相似问题