c# - DocumentDb 无法处理列名中的连字符 (-)

标签 c# azure-cosmosdb

我正在将以下 XML 保存到 DocumentDB:

<DocumentDbTest_Countries> 
  <country>C25103657983</country> 
  <language>C25103657983</language> 
  <countryCode>383388823</countryCode>
  <version>2015-08-25T08:36:59:982.3552</version>
  <integrity>
     <hash-algorithm>sha1</hash-algorithm>
     <hash /> 
  </integrity>
  <context-info> 
     <created-by>unittestuser</created-by> 
     <created-on>2015/08/25 08:36:59</created-on> 
     <created-time-zone>UTC</created-time-zone> 
     <modified-by>unittestuser</modified-by>
     <modified-on>2015/08/25 08:36:59</modified-on> 
     <modified-time-zone>UTC</modified-time-zone>
  </context-info>
</DocumentDbTest_Countries>

它被保存到 DocumentDB 中,如下所示:

{
"DocumentDbTest_Countries": {
"integrity": {
   "hash-algorithm": "sha1",
   "hash": ""
  },
"context-info": {
  "created-by": "unittestuser",
  "created-on": "2015/08/25 08:36:59",
  "created-time-zone": "UTC",
  "modified-by": "unittestuser",
  "modified-on": "2015/08/25 08:36:59",
  "modified-time-zone": "UTC"
},
"country": "C25103657983",
"language": "C25103657983",
"countryCode": 383388823,
"version": "2015-08-25T08:36:59:982.3552"
},
"id": "f917945d-eaee-4eff-944d-dae366de7be1"
}

如您所见,列名确实在 DocumentDB 中保存了连字符 (-)(显然没有任何类型的错误/异常/警告)但是当我尝试进行查找时它在 查询资源管理器。似乎无法搜索带连字符的列名。这是真的?或者,我错过了什么吗?有人可以指点我在某处关于此限制的文档吗?

最佳答案

对于使用特定字符(空格、“@”、“-”等)或与 SQL 关键字冲突的字段名称,您必须使用带引号的属性访问器语法。所以不要写:

SELECT * FROM c WHERE c.context-info.created-by = "unittestuser"

写:

SELECT * FROM c WHERE c["context-info"]["created-by"] = "unittestuser"

关于c# - DocumentDb 无法处理列名中的连字符 (-),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32199469/

相关文章:

c# - 调用主体中包含 JObject 的 Web Api

javascript - Node.js 中的 Azure DocumentDB 存储过程执行现有的

azure - 如何编写azure cosmos数据库复杂的选择查询

c# - 如何通过rs485串口发送和接收?

c# - MSMQ - 反复处理的消息

c# - 通用对象需要强制转换,即使它实现了所需的接口(interface)

javascript - 解决延迟不按预期工作

azure - 如何以编程方式创建 CosmosDB 用户定义函数

c# - 在连接 Azure Cosmos DB API for MongoDB 时,如果 ConnectionModeSwitch 设置为 UseConnectionMode,则无法使用 DirectConnection

c# - 从 Windows Phone 7 连接到 MYSQL