gpt4 book ai didi

asp.net-core - Cosmos DB "Partial Update"/补丁,无法将新属性值设置为 null

转载 作者:行者123 更新时间:2023-12-02 01:51:44 25 4
gpt4 key购买 nike

我正在试用 Cosmos DB SDK 的新 Patch/Partial Update-functionality (对于 .NET)

添加新属性时我使用

 var patchOperations = new List<PatchOperation>(){
PatchOperation.Add<string>("/FavoriteColor", **null**)
};


await container.PatchItemAsync<T>(
id: myId,
partitionKey: new PartitionKey(myPk),
patchOperations: patchOperations);

问题是,如果我将第二个参数设置为 null(消息 “Value cannot be null”),它会抛出 PatchOperation-Add()。我可以设置任何非空字符串并且效果很好。我只是想知道这是否还不受支持,或者我是否遗漏了什么。

最佳答案

感谢 github 用户 rvdvelden ( source ),这项变通工作似乎完美无缺:

private JToken NullValue { get { return new JProperty("nullValue", null).Value; } }

这样使用:

operations.Add(PatchOperation.Set("\customer", value ?? NullValue));

关于asp.net-core - Cosmos DB "Partial Update"/补丁,无法将新属性值设置为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70189709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com