internal static async Task <TResult> ExecuteBatchOperationAsync <TResult>(TableBatchOperation batch, CloudTableClient client, CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext, CancellationToken cancellationToken) where TResult : class { TableOperationType currentOperationType = batch.First().OperationType; batch.First(); try { List <Document> list = new List <Document>(); List <TableOperationType> list2 = new List <TableOperationType>(); List <string> list3 = new List <string>(); foreach (TableOperation item2 in batch) { currentOperationType = item2.OperationType; Document item = (item2.OperationType != TableOperationType.Retrieve) ? EntityHelpers.GetDocumentFromEntity(item2.Entity, operationContext, requestOptions) : EntityTranslator.GetDocumentWithPartitionAndRowKey(item2.RetrievePartitionKey, item2.RetrieveRowKey); list.Add(item); list2.Add(item2.OperationType); list3.Add((item2.Entity == null) ? string.Empty : EtagHelper.ConvertToBackEndETagFormat(item2.Entity.ETag)); } RequestOptions requestOptions2 = GetRequestOptions(batch.batchPartitionKey, requestOptions); Uri storedProcedureUri = UriFactory.CreateStoredProcedureUri("TablesDB", table.Name, "__.sys.tablesBatchOperation"); StoredProcedureResponse <string> storedProcedureResponse = await table.ServiceClient.DocumentClient.ExecuteStoredProcedureAsync <string>(storedProcedureUri, requestOptions2, new object[3] { list.ToArray(), list2.ToArray(), list3.ToArray() }); JArray jArray = JArray.Parse(storedProcedureResponse.Response); TableBatchResult tableBatchResult = new TableBatchResult(); tableBatchResult.RequestCharge = storedProcedureResponse.RequestCharge; for (int i = 0; i < jArray.Count; i++) { tableBatchResult.Add(GetTableResultFromDocument(batch[i], jArray[i].ToObject <Document>(), operationContext, requestOptions, storedProcedureResponse.SessionToken, 0.0)); } return(tableBatchResult as TResult); } catch (Exception ex) { DocumentClientException ex2 = ex as DocumentClientException; if (ex2 != null && ex2.StatusCode == HttpStatusCode.BadRequest && ex2.Message.Contains("Resource Not Found") && currentOperationType == TableOperationType.Retrieve) { TableBatchResult tableBatchResult2 = new TableBatchResult(); tableBatchResult2.Add(new TableResult { Etag = null, HttpStatusCode = 404, Result = null }); tableBatchResult2.RequestCharge = ex2.RequestCharge; return(tableBatchResult2 as TResult); } TableErrorResult tableErrorResult = ex.TranslateDocumentErrorForStoredProcs(null, batch.Count); RequestResult requestResult = GenerateRequestResult(tableErrorResult.ExtendedErroMessage, tableErrorResult.HttpStatusCode, tableErrorResult.ExtendedErrorCode, tableErrorResult.ExtendedErroMessage, tableErrorResult.ServiceRequestID, tableErrorResult.RequestCharge); StorageException ex3 = new StorageException(requestResult, requestResult.ExtendedErrorInformation.ErrorMessage, ex); if (ex2 != null) { PopulateOperationContextForBatchOperations(operationContext, ex3, ex2.ActivityId); } throw ex3; } }