为什么在使用CosmosClient升级项目时,为什么要显式地包含PartitionKey?

编程入门 行业动态 更新时间:2024-10-25 12:17:47
本文介绍了为什么在使用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.

docs.microsoft/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需要解析该项目并弄清楚哪个是正确的属性,以及所有花费计算时间的事情.参考 github/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 github/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?

本文发布于:2023-11-24 03:39:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623839.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   CosmosClient   PartitionKey   要显式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!