在Azure CosmosDB中查询骆驼案例JSON文档

时间:2018-11-28 06:23:03

标签: json camelcasing azure-cosmosdb-sqlapi

我用\locationId而不是\LocationId这样的驼峰分区键创建了集合。另外,在cosmosdb中插入/更新文档时,我还使用以下代码将它们添加为驼峰式:

T entity = null;
var settings = new JsonSerializerSettings 
{ 
      ContractResolver = new CamelCasePropertyNamesContractResolver() 
};

var messageBody = JsonConvert.SerializeObject(entity, Formatting.Indented, settings);

using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(messageBody)))
{
      var res = Resource.LoadFrom<Document>(memoryStream);
      await _client.UpsertDocumentAsync((await _collection).SelfLink, res, option);
}

但是,使用linq条件检索任何文档时,结果始终为null。我已经用[JsonProperty(PropertyName = "id")]

装饰了所有CosmosDB T类型

我在这里想念什么吗?

0 个答案:

没有答案