Batch Operation for Azure Storage/Cosmos Table - Limit

Yep... the limit for batch operations is 100 entries or 4MB, which ever is lesser/smaller.
Here's some code to parcel out the batch operation if you're in a for/foreach loop:


using Microsoft.Azure.Cosmos.Table;

TableBatchOperation batch = new TableBatchOperation();
foreach (var myEntity in results)
{
    batch.Add(TableOperation.Delete(myEntity));
    if (batch.Count % 50 == 0)
    {
        table.ExecuteBatch(batch);
        batch = new TableBatchOperation();
    }
}
if(batch.Count > 0)
    table.ExecuteBatch(batch);

Comments