为什么在使用CosmosClient升级项目时,为什么要显式地包含PartitionKey? [英] Why would I ever want to explicitly include a PartitionKey when upserting an item with CosmosClient?

查看:42
本文介绍了为什么在使用CosmosClient升级项目时,为什么要显式地包含PartitionKey?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UpsertItemAsync 有一个可选参数,您可以在其中指示 PartitionKey .

UpsertItemAsync has an optional parameter where you can indicate the PartitionKey.

这是针对新" CosmosClient的,而不是针对旧" CosmosClient的.

This is for the 'new' CosmosClient and not for the 'old' DocumentClient.

https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.cosmos.container.upsertitemasync?view=azure-dotnet

如文档所述-它是可选的,因为如果您不提供该选项,它将自动从项目中提取.那不是很完美吗?

As the documentation says - it is optional because if you do not supply one, it will be automatically extracted from the item. Isn't that perfect?

在任何您不想要的情况下都有可能的情况吗?

Is there any conceivable situation under any circumstances where that is not what you want?

推荐答案

因为提取PartitionKey意味着SDK需要解析该项目并弄清楚哪个是正确的属性,以及所有花费计算时间的事情.参考 https://github.com/Azure/azure-cosmos-dotnet-v3/blob/master/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.Items.cs#L506

Because extracting the PartitionKey means that the SDK needs to parse the item and figure out which is the correct attribute and all that takes computational time. Reference https://github.com/Azure/azure-cosmos-dotnet-v3/blob/master/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.Items.cs#L506

如果您提前知道PartitionKey值是多少,它将提高操作的整体性能.

If you know ahead of time which is the PartitionKey value, it will improve the overall performance of the operation.

这篇关于为什么在使用CosmosClient升级项目时,为什么要显式地包含PartitionKey?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆