【发布时间】:2014-11-26 13:53:12
【问题描述】:
这是一个显示问题的基本示例。
我有一个 MobileServiceClient 和离线 SyncTable
private MobileServiceClient client = new MobileServiceClient("http://localhost:19087/");
private IMobileServiceSyncTable<TodoItem> todoTable;
我在客户端上有一个 TodDoItem.cs
public class TodoItem
{
public string Id { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string Text { get; set; }
public bool Complete { get; set; }
}
我像这样初始化我的离线数据库
async Task Initialise()
{
if (!client.SyncContext.IsInitialized)
{
var store = new MobileServiceSQLiteStore("todo.db");
store.DefineTable<TodoItem>();
await client.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());
}
todoTable = client.GetSyncTable<TodoItem>();
}
并在此处将在线数据与离线数据同步
async Task RefreshData()
{
await todoTable.PullAsync("todo", null);
var result = await todoTable.ToCollectionAsync();
listItems.ItemsSource = result;
}
现在这里的问题是 CreatedAt 属性始终为空。如果我使属性不可为空,则它显示为日期 01/01/0001(基本上是 DateTime.Min)。数据库中的记录具有正确的日期。使用 fiddler 进行测试显示正确的日期正在从 MobileService 进行序列化
如果我更改为在线环境,即
private IMobileServiceTable<TodoItem> todoTable;
然后一切都按预期工作。 CreatedAt 显示正确的日期。 我已经尝试了Carlos' fix here 所示的 JsonConverter,但这不起作用,因为日期已经是 01/01/0001(错误),因为它进入转换器。 我真的需要按日期订购记录并且无法弄清楚为什么这在离线环境中不起作用。任何帮助表示赞赏。
【问题讨论】:
标签: c# sqlite azure offline azure-mobile-services