AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.
In addition to deleting an item, you can also return the item's attribute values in the same operation, using the ReturnValues parameter.
Unless you specify conditions, the DeleteItem is an idempotent operation; running it multiple times on the same item or attribute does not result in an error response.
Conditional deletes are useful for deleting items only if specific conditions are met. If those conditions are met, DynamoDB performs the delete. Otherwise, the item is not deleted.
Namespace: Amazon.DynamoDBv2.Model
Assembly: AWSSDK.dll
Version: (assembly version)
public class DeleteItemRequest : AmazonDynamoDBRequest IRequestEvents
The DeleteItemRequest type exposes the following members
Name | Description | |
---|---|---|
DeleteItemRequest() | Empty constructor used to set properties independently even when a simple constructor is available | |
DeleteItemRequest(string, Dictionary<String, AttributeValue>) | ||
DeleteItemRequest(string, Dictionary<String, AttributeValue>, ReturnValue) |
Name | Type | Description | |
---|---|---|---|
ConditionalOperator | Amazon.DynamoDBv2.ConditionalOperator |
Gets and sets the property ConditionalOperator. This is a legacy parameter, for backward compatibility. New applications should use ConditionExpression instead. Do not combine legacy parameters and expression parameters in a single API call; otherwise, DynamoDB will return a ValidationException exception. A logical operator to apply to the conditions in the Expected map:
If you omit ConditionalOperator, then The operation will succeed only if the entire map evaluates to true. This parameter does not support attributes of type List or Map. |
|
ConditionExpression | System.String |
Gets and sets the property ConditionExpression.
A condition that must be satisfied in order for a conditional DeleteItem to succeed. An expression can contain any of the following:
For more information on condition expressions, see Specifying Conditions in the Amazon DynamoDB Developer Guide. ConditionExpression replaces the legacy ConditionalOperator and Expected parameters. |
|
Expected | System.Collections.Generic.Dictionary<System.String, Amazon.DynamoDBv2.Model.ExpectedAttributeValue> |
Gets and sets the property Expected. This is a legacy parameter, for backward compatibility. New applications should use ConditionExpression instead. Do not combine legacy parameters and expression parameters in a single API call; otherwise, DynamoDB will return a ValidationException exception. A map of attribute/condition pairs. Expected provides a conditional block for the DeleteItem operation. Each element of Expected consists of an attribute name, a comparison operator, and one or more values. DynamoDB compares the attribute with the value(s) you supplied, using the comparison operator. For each Expected element, the result of the evaluation is either true or false. If you specify more than one element in the Expected map, then by default all of the conditions must evaluate to true. In other words, the conditions are ANDed together. (You can use the ConditionalOperator parameter to OR the conditions instead. If you do this, then at least one of the conditions must evaluate to true, rather than all of them.) If the Expected map evaluates to true, then the conditional operation succeeds; otherwise, it fails. Expected contains the following:
For usage examples of AttributeValueList and ComparisonOperator, see Legacy Conditional Parameters in the Amazon DynamoDB Developer Guide. For backward compatibility with previous DynamoDB releases, the following parameters can be used instead of AttributeValueList and ComparisonOperator:
The Value and Exists parameters are incompatible with AttributeValueList and ComparisonOperator. Note that if you use both sets of parameters at once, DynamoDB will return a ValidationException exception. This parameter does not support attributes of type List or Map. |
|
ExpressionAttributeNames | System.Collections.Generic.Dictionary<System.String, System.String> |
Gets and sets the property ExpressionAttributeNames.
One or more substitution tokens for attribute names in an expression. The following are some use cases for using ExpressionAttributeNames:
Use the # character in an expression to dereference an attribute name. For example, consider the following attribute name:
The name of this attribute conflicts with a reserved word, so it cannot be used directly in an expression. (For the complete list of reserved words, see Reserved Words in the Amazon DynamoDB Developer Guide). To work around this, you could specify the following for ExpressionAttributeNames:
You could then use this substitution in an expression, as in this example:
Tokens that begin with the : character are expression attribute values, which are placeholders for the actual value at runtime. For more information on expression attribute names, see Accessing Item Attributes in the Amazon DynamoDB Developer Guide. |
|
ExpressionAttributeValues | System.Collections.Generic.Dictionary<System.String, Amazon.DynamoDBv2.Model.AttributeValue> |
Gets and sets the property ExpressionAttributeValues.
One or more values that can be substituted in an expression. Use the : (colon) character in an expression to dereference an attribute value. For example, suppose that you wanted to check whether the value of the ProductStatus attribute was one of the following:
You would first need to specify ExpressionAttributeValues as follows: { ":avail":{"S":"Available"}, ":back":{"S":"Backordered"}, ":disc":{"S":"Discontinued"} } You could then use these values in an expression, such as this:
For more information on expression attribute values, see Specifying Conditions in the Amazon DynamoDB Developer Guide. |
|
Key | System.Collections.Generic.Dictionary<System.String, Amazon.DynamoDBv2.Model.AttributeValue> |
Gets and sets the property Key.
A map of attribute names to AttributeValue objects, representing the primary key of the item to delete. For the primary key, you must provide all of the attributes. For example, with a simple primary key, you only need to provide a value for the partition key. For a composite primary key, you must provide values for both the partition key and the sort key. |
|
ReturnConsumedCapacity | Amazon.DynamoDBv2.ReturnConsumedCapacity | Gets and sets the property ReturnConsumedCapacity. | |
ReturnItemCollectionMetrics | Amazon.DynamoDBv2.ReturnItemCollectionMetrics |
Gets and sets the property ReturnItemCollectionMetrics.
Determines whether item collection metrics are returned. If set to |
|
ReturnValues | Amazon.DynamoDBv2.ReturnValue |
Gets and sets the property ReturnValues.
Use ReturnValues if you want to get the item attributes as they appeared before they were deleted. For DeleteItem, the valid values are:
|
|
TableName | System.String |
Gets and sets the property TableName.
The name of the table from which to delete the item. |
This example shows how to delete an item in a table.
// Create a client AmazonDynamoDBClient client = new AmazonDynamoDBClient(); // Define item key // Hash-key of the target item is string value "Mark Twain" // Range-key of the target item is string value "The Adventures of Tom Sawyer" Dictionary<string, AttributeValue> key = new Dictionary<string, AttributeValue> { { "Author", new AttributeValue { S = "Mark Twain" } }, { "Title", new AttributeValue { S = "The Adventures of Tom Sawyer" } } }; // Create DeleteItem request DeleteItemRequest request = new DeleteItemRequest { TableName = "SampleTable", Key = key }; // Issue request client.DeleteItem(request);
.NET Framework:
Supported in: 4.5, 4.0, 3.5
.NET for Windows Store apps:
Supported in: Windows 8.1, Windows 8
.NET for Windows Phone:
Supported in: Windows Phone 8.1, Windows Phone 8