Amazon AWS SDK Guide de l'utilisateur Page 62 : Print an Item
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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
Fichier PDF · ·
Questions sur Amazon AWS SDK
Pas encore de questions sur ce manuel. Posez la première.
Produits connexes et manuels pour Logiciel Amazon AWS SDK
- Logiciel Amazon Redshift Manuel d'utilisateur
(24 pages) - Logiciel Amazon Redshift Manuel d'utilisateur
(11 pages) - Logiciel Amazon AWS SDK Guide de l'utilisateur
(73 pages)