【问题标题】:Azure CosmosDB SQL APi how to save date created when i create a documentAzure CosmosDB SQL APi 如何保存创建文档时创建的日期
【发布时间】:2021-02-22 19:06:23
【问题描述】:

我是使用 SQL API 的 Azure CosmosDB 新手。我正在开发一个 ASP.Net 核心 api 来创建一个简单的客户。我想存储创建的日期。这该怎么做?我有属性 _ts 在客户实体更新时不断更新。但我想存储创建日期。

 public abstract class BaseCosmosEntity
    {
        public string Id { get; set; }

        [JsonProperty("_ts")]
        public string ts { get; set; }

        [JsonProperty("_type")]
        public string Type { get; set; }
    }

谁能帮助如何将 DateCreated 存储在 Azure cosmosdb 中?

谢谢

【问题讨论】:

  • 只需添加一个用于创建日期的日期属性。

标签: c# azure-cosmosdb asp.net-core-webapi


【解决方案1】:

假设您使用的是 .NET SDK,您可以使用DateTime 属性,该属性将序列化为 ISO 8601 格式。我在我的实体类中使用它:

public DateTime TimeCreated { get; set; }

请务必在您的创建操作中进行设置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-14
    • 2013-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多