我正在使用 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 元数据表也不包含每个操作的日期。
最佳答案
createdAt 和updatedAt 字段由数据库更新,而不是由您更新。如果您将记录推送到服务器,它们将为您填充。
关于.net - 为什么 MobileServiceSQLiteStore 数据库中的createdAt、deleted和updatedAt列为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39578143/