private async Task <IList <TableResult> > ExecuteAsync( TableBatchOperation batch, CloudTableClient client, CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext) { if (batch.Count == 0) { throw new InvalidOperationException(SR.EmptyBatchOperation); } if (batch.Count > 100) { throw new InvalidOperationException(SR.BatchExceededMaximumNumberOfOperations); } try { string script = StellarBatchExecutor.MakeCreateDocumentsScript(); StoredProcedure sproc = await this.GetOrCreateStoredProcedureAsync(table, StellarBatchExecutor.BulkInsertOrMergeOrUpdate, script); List <Document> javaScriptParams1 = new List <Document>(); List <TableOperationType> javaScriptParams2 = new List <TableOperationType>(); List <string> javaScriptParams3 = new List <string>(); string partitionKey = batch.FirstOrDefault().PartitionKey; foreach (TableOperation operation in batch) { Document document = null; if (operation.OperationType == TableOperationType.Retrieve) { document = this.GetDocumentWithPartitionAndRowKey(operation.RetrievePartitionKey, operation.RetrieveRowKey); } else { document = EntityHelpers.GetDocumentFromEntity(operation.Entity, operationContext, requestOptions); } javaScriptParams1.Add(document); javaScriptParams2.Add(operation.OperationType); javaScriptParams3.Add(operation.Entity == null ? "" : operation.Entity.ETag); } RequestOptions docdbRequestOptions = new RequestOptions { PartitionKey = new PartitionKey(partitionKey) }; StoredProcedureResponse <string> response = await table.ServiceClient.DocumentClient.ExecuteStoredProcedureAsync <string>(sproc.SelfLink, docdbRequestOptions, javaScriptParams1.ToArray(), javaScriptParams2.ToArray(), javaScriptParams3.ToArray()); JArray jArray = JArray.Parse(response.Response); List <TableResult> tableResults = new List <TableResult>(); for (int i = 0; i < jArray.Count; i++) { tableResults.Add(GetTableResultFromDocument(batch[i], jArray[i].ToObject <Document>(), operationContext)); } return(tableResults); } catch (Exception ex) { throw EntityHelpers.GetTableResultFromException(ex); } }