Cosmos DB 存储过程调用 returns "PartitionKey value must be supplied for this operation"

Cosmos DB Stored Procedure Call returns "PartitionKey value must be supplied for this operation"

我正在开发一个 C# Azure Function 并希望在 Cosmos DB 中执行一个存储过程,如下所示:

string sprocName = "testSPROC";
int partitionId = contentJSON.partitionid;
RequestOptions requestOptions = new RequestOptions { PartitionKey = new PartitionKey(partitionId), EnableScriptLogging = true };
var sprocResponse = await client.ExecuteStoredProcedureAsync<Object>(
    UriFactory.CreateStoredProcedureUri(databaseName, collectionName, sprocName),
    contentJSON,
    requestOptions);

CosmosDB 集合是按分区 ID 分区的。但是当我要执行存储过程时,它 returns:

PartitionKey value must be supplied for this operation

为什么?

乍一看一切正常,但传递给 SPROC 的参数顺序和请求选项是错误的。必须是

var sprocResponse = await client.ExecuteStoredProcedureAsync<Object>(
                    UriFactory.CreateStoredProcedureUri(databaseName, collectionName, sprocName),
                    requestOptions,
                    contentJSON);

然后就可以了。