.net - 为什么 MobileServiceSQLiteStore 数据库中的createdAt、deleted和updatedAt列为空?

标签 .net sqlite azure uwp azure-mobile-services

我正在使用 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;
    }
}

这是数据库中的结果记录:

Database record screenshot

更新 使用 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/

相关文章:

c# - 基类属性的自定义序列化

c# - Microsoft Dynamics (Navision) 与 C# .NET

iphone - iPhone应用程序中的两个sqlite db

azure - 我需要更改 Azure 应用服务中的哪些设置才能允许在 App_Offline 中使用 Base64 图像?

Azure WebJob 队列触发器执行

c# - 如何在Azure API函数中返回变量并通过移动应用程序中的调用异步函数读取它

.net - 将 ASP.NET MVC 4 项目从 .NET 4.5 转换为 .NET 4

c# - 未作为根连接时,无法将类型 'System.DBNull' 的对象强制转换为类型 'System.String'

java - 如何将带有缩写记录的sqlite数据库添加到android项目中

python - !EXE Tkinter 问题 : datas are LOST when I quit the program