我在使用 Microsoft.Azure.Cosmos 3.2.0 版时遇到了一些问题,
跑步时
await this.Container.CreateItemAsync<LogEntity>(logEntity, new PartitionKey("anythingIPutHere"));
Run Code Online (Sandbox Code Playgroud)
它抛出
Microsoft.Azure.Cosmos.CosmosException HResult=0x80131500
消息=响应状态代码不表示成功:400 子状态:1001 原因:(消息:{“错误”:[“从文档中提取的分区密钥与标题中指定的不匹配"]}
但如果我把
await this.Container.CreateItemAsync<LogEntity>(logEntity, new PartitionKey(logEntity.Id));
Run Code Online (Sandbox Code Playgroud)
它有效,并且是唯一有效的情况。
我也试过
partitionKeyJSON 属性名称但没有成功;我查看了 Microsoft 站点上的一些指南,似乎您可以将分区键指定为某个字符串,而不必是 id 或使用对象上的属性名称指定;那么为什么会这样呢?
Gab*_* P. 26
我在创建容器时忽略了这一点
this.Container = await this.Database.CreateContainerIfNotExistsAsync("testContainer", "/id");
Run Code Online (Sandbox Code Playgroud)
我已指定partitionKeyPath为 beeing /id。
似乎分区键必须驻留在对象上,并且必须具有 partitionKeyPath 属性名称的 json 属性,而没有 / 喜欢:
[JsonProperty(PropertyName = "partition")]
public string Partition { get; set; }
Run Code Online (Sandbox Code Playgroud)
如果partitionKeyPath是/partition
this.Container = await this.Database.CreateContainerIfNotExistsAsync("testContainer", "/partition");
Run Code Online (Sandbox Code Playgroud)
对不起,如果这很明显,我刚刚开始玩 CosmoDb。
| 归档时间: |
|
| 查看次数: |
13431 次 |
| 最近记录: |