Batch Table Operations - Understanding Table Storage - Part Five

A batch operation is a collection of table operations which are executed by the Storage Service REST API as a single atomic operation, by invoking an Entity Group Transaction. A batch operation may contain up to 100 individual table operations, with the requirement that each operating entity must have same partition key. A batch with a retrieve operation cannot contain any other operations. Note that the total payload of a batch operation is limited to 4MB.

Step 1

Open the previous project remove all the methods and its calls from the Main method except RetrieveAllCustomers method and its method call. Add the following method to your class which will perform the batch operation. Here, it will add three more customers in a single shot.

  1. static void BatchOperation(CloudTable table)  
  2. {  
  3.    TableBatchOperation batch = new TableBatchOperation();  
  4.    var customer3 = new Customer("Customer3""[email protected]""registered");  
  5.    var customer4 = new Customer("Customer4""[email protected]""registered");  
  6.    var customer5 = new Customer("Customer5""[email protected]""registered");  
  7.    batch.Insert(customer3);  
  8.    batch.Insert(customer4);  
  9.    batch.Insert(customer5);  
  10.    table.ExecuteBatch(batch);  
  11. }  
Azure
Step 2

Call the BatchOperation method in your Main function by adding the following code to your main function before the call for RetriveAllCustomers.
  1. BatchOperation(table);

Azure 

Step 3

Run your application and you can see that all the new three records have been added.

Azure


Similar Articles