C# Azure函数-“Azure函数”;从文档中提取的PartitionKey不';t与标题中指定的内容不匹配;关于在门户中创建的容器

C# Azure函数-“Azure函数”;从文档中提取的PartitionKey不';t与标题中指定的内容不匹配;关于在门户中创建的容器,c#,azure,azure-functions,azure-cosmosdb,C#,Azure,Azure Functions,Azure Cosmosdb,我正试图通过CreateItemAsync()方法将一些数据上传到Azure Cosmos Db容器中,代码如下: Database partnersDb = GetCosmosDb(); Container partnersContainer = GetCosmosContainer(partnersDb); try { ItemResponse<PartnerInfo> partnersResponse = await partn

我正试图通过CreateItemAsync()方法将一些数据上传到Azure Cosmos Db容器中,代码如下:

    Database partnersDb = GetCosmosDb();
    Container partnersContainer = GetCosmosContainer(partnersDb);

    try
    {
        ItemResponse<PartnerInfo> partnersResponse = await partnersContainer.CreateItemAsync(partner, new PartitionKey(partner.Id));
    }
    catch (CosmosException e) when (e.StatusCode == HttpStatusCode.Conflict)
    {
        logger.LogInformation($"Item with id {partner.Id} already exists in partners database");
    }
在cosmos db中,我仅为通过“New item”选项手动创建的3个项目获取此信息:


有什么想法吗?

这个错误是由
PartitionKey
的两个值(在您的文档和
CreateItemAsync
方法中)引起的,它们不一样


通过使用此代码,可以获得
PartitionKeyPath

ContainerProperties properties = await container.ReadContainerAsync();             
Console.WriteLine(properties.PartitionKeyPath);

然后将斜杠“/”后面相同名称的值作为分区键传递给
CreateItemAsync
方法可以解决此错误。

CosmosDB使用的API是什么?另外,您知道容器上使用的数据模式吗?我正在使用官方的microsoft nuget访问它:最新版本的microsoft.Azure.Cosmos。此外,容器中的3个项目的数据结构(已手动上载)与我想要共同上载的项目不同(如果这是您要求的,并且我可以访问它们)。您可以通过使用此代码获取分区密钥路径
ContainerProperties properties=wait container.readcontainerSync();             Console.WriteLine(properties.PartitionKeyPath)Steve回答了我需要的所有问题:)在获得partitionKeyPath后,我只需将与斜杠“/”后面相同名称的变量作为partitionKey传递。
[
    {},
    {},
    {}
]
ContainerProperties properties = await container.ReadContainerAsync();             
Console.WriteLine(properties.PartitionKeyPath);