我在cosmos db中有一个复合分区键,但我不明白如何获取一个项目
List<(string, PartitionKey)> itemsToFind = new();
itemsToFind.Add(("testApi", new PartitionKey("[\"value1\", \"value2\"]")));
var result = await container.ReadManyItemsAsync<MyClass>(items: itemsToFind);
它会抛出
Number of components in the partition key value does not match the definition
但如果 PartitionKey 只接受字符串,我该如何匹配数字?
您查看过文档中的示例吗?
// Build the full partition key path
PartitionKey partitionKey = new PartitionKeyBuilder()
.Add("Microsoft") //TenantId
.Add("8411f20f-be3e-416a-a3e7-dcd5a3c1f28b") //UserId
.Add("0000-11-0000-1111") //SessionId
.Build();
// Perform a point read
ItemResponse<UserSession> readResponse = await container.ReadItemAsync<UserSession>(
id,
partitionKey
);