【发布时间】:2016-02-03 15:17:27
【问题描述】:
我正在尝试使用 here 记录的 C# 低级 API 更新 DynamoDB 表中的项目
这是我实现这一目标的尝试:
var response = DynamoClientProvider.Current.UpdateItem(new UpdateItemRequest
{
TableName = "MyTable",
Key = {{"TableId", new AttributeValue {S = "12345"}}},
ExpressionAttributeNames =
{
{"#T","Timestamp"},
{"#D","Data"}
{"#K","MyKey"}
},
ExpressionAttributeValues =
{
{":Timestamp", new AttributeValue("2016-2-3 00:00:00.000")},
{":Data", new AttributeValue("some data")}
{":MyKey", new AttributeValue("some other data")}
},
UpdateExpression = "SET #D = :Data, #T = :Timestamp, #K = :MyKey",
ConditionExpression = "attribute_not_exists (Data)",
ReturnValues = ReturnValue.ALL_OLD
});
此代码运行良好,但是当MyKey 为空字符串时会出现问题。当它为空时,我收到以下错误:
Amazon.DynamoDBv2.AmazonDynamoDBException:ExpressionAttributeValues 包含无效值:提供的 AttributeValue 为空,必须包含 正是 key 支持的数据类型之一:MyKey
因此,我尝试传入一个空的AttributeValue,以便在这种情况下通过将其设置为以下属性来删除该属性:
new AttributeValue{NULL = true}
但是,这会将值设置为 True 的字符串文字
【问题讨论】:
标签: c# amazon-web-services amazon-dynamodb aws-sdk