AWS SDK for .NET Documentation
BatchWriteItemRequest Class
AmazonAmazon.DynamoDB.ModelBatchWriteItemRequest Did this page help you?   Yes   No    Tell us about it...
Container for the parameters to the BatchWriteItem operation.

Allows to execute a batch of Put and/or Delete Requests for many tables in a single call. A total of 25 requests are allowed.

There are no transaction guarantees provided by this API. It does not allow conditional puts nor does it support return values.

Declaration Syntax
C#
public class BatchWriteItemRequest : AmazonWebServiceRequest
Members
All MembersConstructorsMethodsProperties



IconMemberDescription
BatchWriteItemRequest()()()()
Initializes a new instance of the BatchWriteItemRequest class

Equals(Object)
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
GetHashCode()()()()
Serves as a hash function for a particular type.
(Inherited from Object.)
GetType()()()()
Gets the type of the current instance.
(Inherited from Object.)
RequestItems
A map of table name to list-of-write-requests. Used as input to the BatchWriteItem API call

Constraints:

Length
1 - 25


ToString()()()()
Returns a string that represents the current object.
(Inherited from Object.)
WithRequestItems(array<KeyValuePair<(Of <<'(String, List<(Of <<'(WriteRequest>)>>)>)>>)>[]()[][]) Obsolete.
Adds the KeyValuePairs to the RequestItems dictionary.

Examples

The following examples show how to batch items into two tables.

This example will construct a batch-write collection for the first table in the request. The request will include two Put operations and one Delete operation.

CopyBatchWrite sample - First table
// Create items to put into first table
Dictionary<string, AttributeValue> item1 = new Dictionary<string,AttributeValue>();
item1["Author"] = new AttributeValue { S = "Mark Twain" };
item1["Title"] = new AttributeValue { S = "A Connecticut Yankee in King Arthur's Court" };
item1["Pages"] = new AttributeValue { N = "575" };
Dictionary<string, AttributeValue> item2 = new Dictionary<string, AttributeValue>();
item2["Author"] = new AttributeValue { S = "Booker Taliaferro Washington" };
item2["Title"] = new AttributeValue { S = "My Larger Education" };
item2["Pages"] = new AttributeValue { N = "313" };
item2["Year"] = new AttributeValue { N = "1911" };

// Create key for item to delete from first table
//  Hash-key of the target item is string value "Mark Twain"
//  Range-key of the target item is string value "Tom Sawyer, Detective"
Key keyToDelete1 = new Key
{
    HashKeyElement = new AttributeValue { S = "Mark Twain" },
    RangeKeyElement = new AttributeValue { S = "Tom Sawyer, Detective" }
};

// Construct write-request for first table
List<WriteRequest> sampleTableItems = new List<WriteRequest>();
sampleTableItems.Add(new WriteRequest
{
    PutRequest = new PutRequest { Item = item1 }
});
sampleTableItems.Add(new WriteRequest
{
    PutRequest = new PutRequest { Item = item2 }
});
sampleTableItems.Add(new WriteRequest
{
    DeleteRequest = new DeleteRequest { Key = keyToDelete1 }
});

This example will construct a batch-write collection for the second table in the request. The request will include one Delete operation.

CopyBatchWrite sample - Second table
// Create key for item to delete from second table
//  Hash-key of the target item is string value "Francis Scott Key Fitzgerald"
Key keyToDelete2 = new Key
{
    HashKeyElement = new AttributeValue { S = "Francis Scott Key Fitzgerald" },
};

// Construct write-request for first table
List<WriteRequest> authorsTableItems = new List<WriteRequest>();
authorsTableItems.Add(new WriteRequest
{
    DeleteRequest = new DeleteRequest { Key = keyToDelete2 }
});

This example will construct the BatchWrite request from the two earlier-created collections, will issue the call and in case some items are not processed, will attempt to write the remaining items.

CopyBatchWrite sample - Service calls
// Create a client
AmazonDynamoDBClient client = new AmazonDynamoDBClient();

// Construct table-keys mapping
Dictionary<string, List<WriteRequest>> requestItems = new Dictionary<string, List<WriteRequest>>();

BatchWriteItemRequest request = new BatchWriteItemRequest();
requestItems["SampleTable"] = sampleTableItems;
requestItems["AuthorsTable"] = authorsTableItems;

BatchWriteItemResult result;
do
{
    // Issue request and retrieve items
    result = client.BatchWriteItem(request).BatchWriteItemResult;

    // Some items may not have been processed!
    //  Set RequestItems to the result's UnprocessedItems and reissue request
    request.RequestItems = result.UnprocessedItems;

} while (result.UnprocessedItems.Count > 0);
Inheritance Hierarchy
Object
AmazonWebServiceRequest
 BatchWriteItemRequest
See Also

Assembly: AWSSDK (Module: AWSSDK) Version: 1.5.60.0 (1.5.60.0)