azure-cosmosdb - Azure 文档数据库 ID

标签 azure-cosmosdb

我在使用 azure Document Db 时遇到了一个问题,或者对 Id 感到困惑。我知道 DocumentDb 为每个文档生成一个“小写”“id”属性,这对我来说没问题,但我似乎无法弄清楚如何在使用 .net 客户端时获取这个“id”。我的代码如下所示

 public class Company
    {
        public Guid Id { get; set; } // this somehow does not get mapped to the "id" in the document.
        public string Name { get; set; }
        public string Address { get; set; }

    }

所以当我查询时

client.CreateDocumentQuery<Company>(collection.DocumentsLink).ToList();

id 属性未映射。我想我还没有理解文档数据库中的 ID 概念以及它如何正确映射到您的实体。 非常感谢任何帮助。

最佳答案

尝试将您的公司实体更改为

    [JsonProperty("id")]
    public String Id { get; set; }

这会将 documentdb 生成的 Id 加载到 id 字段中。

如果这不起作用,请告诉我。

关于azure-cosmosdb - Azure 文档数据库 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34842158/

相关文章:

c# - Azure函数: use parameter for SqlQuery from ClaimsPrincipal

azure - 为什么 Azure Cosmos 查询在指定分区键时具有更高的 RU?

sql - 在 Azure Cosmos DB 中获取上个月的数据

c# - 从 azure 函数运行 azure 存储过程

azure-cosmosdb - 对 Azure Cosmos DB 中的嵌套字段建立索引

mongodb - 迁移后 Cosmos DB 请求错误

azure - Cosmos db readDocument api 在存储过程中不起作用

azure-cosmosdb - 处理多种类型的 Cosmos DB 容器的读取?

azure - 使用azure函数查询地理空间

azure - 使用 Azure Function 删除 CosmosDB 条目