我正在开发C#Azure函数,并希望在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集合按partitionid进行分区。但是当我要执行存储过程时,它返回:
此操作必须提供PartitionKey值
为什么?
答案 0 :(得分:1)
乍一看一切都很好,但是传递给SPROC的参数顺序和请求选项是错误的。必须是
var sprocResponse = await client.ExecuteStoredProcedureAsync<Object>(
UriFactory.CreateStoredProcedureUri(databaseName, collectionName, sprocName),
requestOptions,
contentJSON);
然后它起作用。