我在使用 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/