User guide

Get Multiple Items by Using Expressions and Other Item
Attributes
The following example features the Amazon.DynamoDBv2.AmazonDynamoDBClient.Scan method
and a set of expressions to get and then print all items that have a ProductCategory of Bike. Only the
following attributes of the item are returned: Id, Title, and all of the attributes in ProductReviews.
// using Amazon.DynamoDBv2;
// using Amazon.DynamoDBv2.Model;
var client = new AmazonDynamoDBClient();
var request = new ScanRequest
{
TableName = "ProductCatalog",
ProjectionExpression = "Id, Title, #pr",
ExpressionAttributeValues = new Dictionary<string,AttributeValue>
{
{ ":catg", new AttributeValue { S = "Bike" } }
},
ExpressionAttributeNames = new Dictionary<string, string>
{
{ "#pr", "ProductReviews" },
{ "#pc", "ProductCategory" }
},
FilterExpression = "#pc = :catg",
};
var response = client.Scan(request);
foreach (var item in response.Items)
{
// Write out the first page/scan of an item's attribute keys and values.
// PrintItem() is a custom function.
PrintItem(item);
Console.WriteLine("=====");
}
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 #pc to represent the ProductCategory attribute.The
ExpressionAttributeValues property specifies the placeholder :catg to represent the value Bike.
The FilterExpression property specifies that #pc (ProductCategory) must be equal to :catg
(Bike). The call to PrintItem refers to a custom function as described in Print an Item (p. 58).
Print an Item
The following example shows how to print an item's attributes and values.This example is used in the
preceding examples that show how to Get a Single Item by Using Expressions and the Item's Primary
Key (p. 56), Get Multiple Items by Using Expressions and the Table's Primary Key (p. 57), and Get
Multiple Items by Using Expressions and Other Item Attributes (p. 58).
// using Amazon.DynamoDBv2.Model;
// Writes out an item's attribute keys and values.
public static void PrintItem(Dictionary<string, AttributeValue> attrs)
{
Version v2.0.0
58
AWS SDK for .NET Developer Guide
Using Expressions with DynamoDB