您好,我正在尝试读取表格中名为“John”的用户。
date
初始化方法
async private void GetUsers()
{
Initialize();
SyncCoffee();
try
{
await coffeeTable.PullAsync("user", coffeeTable.Where(ct => ct.FirstName == "John" ));
}
catch (Exception er)
{
await DisplayAlert("Alert", "the error: "+er, "ok");
}
}
同步方法
public async Task Initialize()
{
var mainPage = new MainPage();
if (isInitialised)
{
return;
}
MobileServiceClient client = new MobileServiceClient("database link");
const string path = "syncstore.db";
var store = new MobileServiceSQLiteStore(path);
store.DefineTable<User>();
await MobileService.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());
coffeeTable = MobileService.GetSyncTable<User>();
isInitialised = true;
}
我一直得到的错误是
System.NullReferenceException:未将对象引用设置为对象的实例。
欢迎任何帮助,因为我对此很陌生。
答案 0 :(得分:0)
等待coffeeTable.PullAsync(“user”,coffeeTable.Where(ct =&gt; ct.FirstName ==“John”));
针对特定用户的拉取操作是正确的。正如Jason所说,您需要在Initialize()
方法中等待SyncCoffee()
,GetUsers
。在coffeeTable
执行之前,null
对象可能会coffeeTable.PullAsync
而Initialize
会失败。对于类似的问题,您可以通过VS进行调试并进入本地代码以缩小范围。此外,我建议你阅读adrian hall关于An Offline Client和An Online Client的书。