Azure batch operations delete several blobs and tables

Posted by reft on Stack Overflow See other posts from Stack Overflow or by reft
Published on 2014-05-31T17:11:04Z Indexed on 2014/06/01 21:28 UTC
Read the original article Hit count: 228

Filed under:

I have a function that deletes every table & blob that belongs to the affected user.

        CloudTable uploadTable = CloudStorageServices.GetCloudUploadsTable();
        TableQuery<UploadEntity> uploadQuery = uploadTable.CreateQuery<UploadEntity>();
        List<UploadEntity> uploadEntity = (from e in uploadTable.ExecuteQuery(uploadQuery)
                                          where e.PartitionKey == "uploads" && e.UserName == User.Idendity.Name
                                          select e).ToList();

        foreach (UploadEntity uploadTableItem in uploadEntity)
        {
            //Delete table
            TableOperation retrieveOperationUploads = TableOperation.Retrieve<UploadEntity>("uploads", uploadTableItem.RowKey);
            TableResult retrievedResultUploads = uploadTable.Execute(retrieveOperationUploads);
            UploadEntity deleteEntityUploads = (UploadEntity)retrievedResultUploads.Result;
            TableOperation deleteOperationUploads = TableOperation.Delete(deleteEntityUploads);
            uploadTable.Execute(deleteOperationUploads);

            //Delete blob
            CloudBlobContainer blobContainer = CloudStorageServices.GetCloudBlobsContainer();
            CloudBlockBlob blob = blobContainer.GetBlockBlobReference(uploadTableItem.BlobName);
            blob.Delete();
        }

Each table got its own blob, so if the list contains 3 uploadentities, the 3 table and the 3 blobs will be deleted.

I heard you can use table batch operations for reduce cost and load. I tried it, but failed miserable. Anyone intrested in helping me:)?

Im guessing tablebatch operations are for tables only, so its a no go for blobs, right?

How would you add tablebatchoperations for this code? Do you see any other improvements that can be done?

Thanks!

© Stack Overflow or respective owner

Related posts about Azure