【发布时间】:2017-01-27 10:28:57
【问题描述】:
我正在使用 Azure 移动应用服务在 UWP 应用程序和 Azure 之间同步数据。我正在使用 MobileServiceSQLiteStore 类设置本地 Sqlite 存储以在本地保存数据,并使用 MobileServiceClient 类将本地更改同步到 Azure,所有这些都按照 Azure 上的快速入门。
我的问题是,当我使用 InsertAsync 方法将数据存储到本地 SqlLite 存储时,存储中的 createdAt、updatedAt 和 deleted 列没有被填充。所有其他列都按预期填充。这些是框架期望在我的模型上使用的标准列,我已按照建议对它们进行了注释(例如 [CreatedAt])
链接的问题突出了同样的问题,但对于 android,以及我已经在做的建议答案,所以没有帮助:Azure Mobile Services Android Offline Example - "createdAt","updatedAt" columns empty
有人可以帮忙吗?
这是我的代码:
using System;
using Microsoft.WindowsAzure.MobileServices;
using Microsoft.WindowsAzure.MobileServices.SQLiteStore;
namespace Test
{
public class SyncManagerTest
{
public SyncManagerTest()
{
var client = new MobileServiceClient(@"https://remote.azurewebsites.net");
var store = new MobileServiceSQLiteStore("test.db");
store.DefineTable<Model>();
client.SyncContext.InitializeAsync(store);
var table = client.GetSyncTable<Model>();
table.InsertAsync(new Model
{
Name = "Test",
AnotherDate = DateTimeOffset.Now,
AnotherBool = true
});
}
}
public class Model
{
[CreatedAt]
public DateTimeOffset? CreatedAt { get; set; } = DateTimeOffset.Now;
[Deleted]
public bool Deleted { get; set; } = false;
public string Id { get; set; }
public string Name { get; set; }
public DateTimeOffset AnotherDate { get; set; }
public bool AnotherBool { get; set; }
[UpdatedAt]
public DateTimeOffset? UpdatedAt { get; set; } = DateTimeOffset.Now;
}
}
这是数据库中的结果记录:
更新 在使用 dotPeek 查看 InsertAsync 的代码后,我发现:
JObject jobject = await this.<>n__1(MobileServiceSyncTable.RemoveSystemPropertiesKeepVersion(serializer.Serialize((object) instance) as JObject));
方法 RemoveSystemPropertiesKeepVersion 正在从写入数据库的 JObject 中删除 createdAt、updatedAt 和 deleted 属性。有谁知道为什么要这样做?我在数据库中看不到为数据库操作保存日期信息的任何地方,同步是如何工作的?即使是框架在Sqlite数据库中创建的__operations元数据表也不包含每个操作的日期。
【问题讨论】:
标签: .net sqlite azure uwp azure-mobile-services