User guide
// using Amazon.DynamoDBv2;
// using Amazon.DynamoDBv2.Model;
var client = new AmazonDynamoDBClient();
var request = new UpdateItemRequest
{
TableName = "ProductCatalog",
Key = new Dictionary<string,AttributeValue>
{
{ "Id", new AttributeValue { N = "301" } }
},
ExpressionAttributeNames = new Dictionary<string, string>
{
{ "#title", "Title" }
},
ExpressionAttributeValues = new Dictionary<string, AttributeValue>
{
{ ":newproduct", new AttributeValue { S = "18\" Girl's Bike" } }
},
UpdateExpression = "SET #title = :newproduct"
};
client.UpdateItem(request);
In the preceding example, the ExpressionAttributeNames property specifies the placeholder #title
to represent the Title attribute.The ExpressionAttributeValues property specifies the placeholder
:newproduct to represent the value 18" Girl's Bike.The UpdateExpression property specifies
to change #title (Title) to :newproduct (18" Girl's Bike).
Delete an Item by Using Expressions
The following example features the Amazon.DynamoDBv2.AmazonDynamoDBClient.DeleteItem
method and a set of expressions to delete the item with Id of 301, but only if the item's Title is
18-Bicycle 301.
// using Amazon.DynamoDBv2;
// using Amazon.DynamoDBv2.Model;
var client = new AmazonDynamoDBClient();
var request = new DeleteItemRequest
{
TableName = "ProductCatalog",
Key = new Dictionary<string,AttributeValue>
{
{ "Id", new AttributeValue { N = "301" } }
},
ExpressionAttributeNames = new Dictionary<string, string>
{
{ "#title", "Title" }
},
ExpressionAttributeValues = new Dictionary<string, AttributeValue>
{
{ ":product", new AttributeValue { S = "18-Bicycle 301" } }
},
ConditionExpression = "#title = :product"
};
client.DeleteItem(request);
Version v2.0.0
62
AWS SDK for .NET Developer Guide
Using Expressions with DynamoDB