我正在创建Windows 10商店应用程序,在调用PullAsync
方法时遇到问题。我长时间使用Azure移动应用程序而且总是使用private IMobileServiceTable<MyTable> table
。现在,我需要在Microsoft中添加一些名为Offline Sync
的支持。按照说明,我没有成功。
这是我的代码。
using Microsoft.WindowsAzure.MobileServices;
using Microsoft.WindowsAzure.MobileServices.Sync;
using Microsoft.WindowsAzure.MobileServices.SQLiteStore;
private IMobileServiceSyncTable<MyTable> OffTable = App.MobileService.GetSyncTable<MyTable>();
private IMobileServiceTable<MyTable> OnTable = App.MobileService.GetTable<MyTable>();
protected ovveride async OnNavigatedTo()
{
if(!App.MobileService.SyncContext.IsInitialized)
{
var store = new MobileServiceSQLiteStore("localstore.db");
store.DefineTable<MyTable>();
await App.MobileService.SyncContext.InitializeAsync(store);
}
await OffTable.PullAsync("uniqueID", OffTable.CreateQuery());
var data = await OffTable.ToCollectionAsync(); //return -> nothing
var data2 = await OnTable.ToCollectionAsync(); //return -> 50 rows
}
MyTable.cs
using Microsoft.WindowsAzure.MobileServices;
using Newtosoft.Json;
[DataTable("MyTable")]
public sealed class MyTable
{
[JsonProperty]
public int ID { get; set;}
[JsonProperty]
public string Field1 { get; set; }
//...
[JsonProperty(PropertyName = "version")]
[Version]
public string Version { get; set; }
[JsonProperty(PropertyName = "deleted")]
[Deleted]
public bool Deleted { get; set; }
[JsonProperty(PropertyName = "updatedAt")]
[UpdatedAt]
public DateTime UpdatedAt { get; set; }
[JsonProperty(PropertyName = "createdAt")]
[CreatedAt]
public DateTime CreatedAt { get; set; }
}
以下是project.json
的值:
"Microsoft.Azure.Mobile.Client": "2.0.1",
"Microsoft.Azure.Mobile.Client.SQLiteStore": "2.0.1"
我做错了什么?
答案 0 :(得分:0)
问题出在服务器端。
所以,基本上你需要通过Azure Portal创建表。您也可以通过SQL Management Studio
创建,但在通过Portal创建时,您将拥有正确格式的createdAt
,updatedAt
,version
和deleted
。因此,如果您通过SQL MGMNT Studio
创建了表格,请转到Portal并点击Create Table
,输入您的表格名称。没关系,您的数据不会被覆盖,然后一切都应该正常工作。