C# 使用AWS低级API将空AttributeValue传递到DynamoDb
我正试图使用文档中的C#低级API更新DynamoDB表中的一个项 以下是我实现这一目标的尝试:C# 使用AWS低级API将空AttributeValue传递到DynamoDb,c#,amazon-web-services,amazon-dynamodb,aws-sdk,C#,Amazon Web Services,Amazon Dynamodb,Aws Sdk,我正试图使用文档中的C#低级API更新DynamoDB表中的一个项 以下是我实现这一目标的尝试: var response = DynamoClientProvider.Current.UpdateItem(new UpdateItemRequest { TableName = "MyTable", Key = {{"TableId", new AttributeValue {S = "12345"}}}, ExpressionAttributeNames = {
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.AmazondynamodException:ExpressionAttributeValues
包含无效值:提供的AttributeValue为空,必须包含
仅支持密钥的一种数据类型:MyKey
因此,我尝试传入nullAttributeValue
,以便在这种情况下通过将属性设置为以下值来删除该属性:
new AttributeValue{NULL = true}
但是,这会将值设置为
True
的字符串文字,我不确定DynamoDB的类型是否可以为空
如果需要删除属性,请使用“SET#D=:Data,#T=:Timestamp REMOVE#K”谢谢,这是一个低级API,因此很有意义