User guide

}
]
},
"ProductReviews": {
"M": {
"FiveStar": {
"SS": [
"My daughter really enjoyed this bike!"
]
},
"ThreeStar": {
"SS": [
"This bike was okay, but I would have preferred it in my color.",
"Fun to ride."
]
}
}
}
}
Get a Single Item by Using Expressions and the Item's
Primary Key
The following example features the Amazon.DynamoDBv2.AmazonDynamoDBClient.GetItem method
and a set of expressions to get and then print the item that has an Id of 205. Only the following attributes
of the item are returned: Id, Title, Description, Color, RelatedItems, Pictures, and
ProductReviews.
// using Amazon.DynamoDBv2;
// using Amazon.DynamoDBv2.Model;
var client = new AmazonDynamoDBClient();
var request = new GetItemRequest
{
TableName = "ProductCatalog",
ProjectionExpression = "Id, Title, Description, Color, #ri, Pictures, #pr",
ExpressionAttributeNames = new Dictionary<string, string>
{
{ "#pr", "ProductReviews" },
{ "#ri", "RelatedItems" }
},
Key = new Dictionary<string, AttributeValue>
{
{ "Id", new AttributeValue { N = "205" } }
},
};
var response = client.GetItem(request);
// PrintItem() is a custom function.
PrintItem(response.Item);
In the preceding example, the ProjectionExpression property specifies the attributes to be returned.
The ExpressionAttributeNames property specifies the placeholder #pr to represent the
ProductReviews attribute and the placeholder #ri to represent the RelatedItems attribute.The call
to PrintItem refers to a custom function as described in Print an Item (p. 58).
Version v2.0.0
56
AWS SDK for .NET Developer Guide
Using Expressions with DynamoDB