Sai Developers Sai Developers - 16 days ago 6
C# Question

How to do batch operation on Azure Storage Table?

I want to insert Multiple Entities into azure table Using Table Operation

I got all data as a List and I just want to save these details into table.

var registrationDescriptionsList = new List<RegistrationDescription>(allRegistrations);

foreach(var retrivedatafromlist in registrationDescriptionsList)
{

batchOperation.Add(TableOperation.Insert(retrivedatafromlist));

}

Answer

I found the Solution. Please find the code.

TableBatchOperation batchOperation = new TableBatchOperation();

foreach (var retrivedatafromlist in registrationDescriptionsList)
{
     NotificationHubServiceBus NhsbObj = new NotificationHubServiceBus();

     var tags = "";

     foreach (var a in retrivedatafromlist.Tags)
     {
         tags = tags + a;
     }

     NhsbObj.PartitionKey = "Sample";
     NhsbObj.RowKey = retrivedatafromlist.RegistrationId;
     NhsbObj.RegistrationId = retrivedatafromlist.RegistrationId;
     NhsbObj.ExpirationDate = retrivedatafromlist.ExpirationTime.ToString();
     NhsbObj.ETag = retrivedatafromlist.ETag;
     NhsbObj.Tags = tags;

     batchOperation.Insert(NhsbObj);
}

table.ExecuteBatch(batchOperation);