public string UpdateDataToOData(Change[] changes, string tableName, string[] headers)
        {
            HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, new Uri(this.odataEndpointURL, "$batch"));
            requestMessage.Headers.Add("DataServiceVersion", this.odataVersion);
            requestMessage.Headers.Add("MaxDataServiceVersion", this.odataMaxVersion);
            
            var setting = new ODataMessageWriterSettings();
            setting.SetContentType(ODataFormat.Batch);
            setting.BaseUri = this.odataEndpointURL;

            var odataHttpRequest = new ODataHttpRequest(requestMessage);
            var messageWriter = new ODataMessageWriter(odataHttpRequest, setting, this.metadata);

            var batchWriter = messageWriter.CreateODataBatchWriter();
            batchWriter.WriteStartBatch();
            
            for (int i = 0; i < changes.Length; i++)
            {
                batchWriter.WriteStartChangeset();
                if (changes[i].operation == "DELETE")
                {
                    createDeleteOperationRequestMessage(ref batchWriter, changes[i], tableName);
                }

                if (changes[i].operation == "UPDATE")
                {
                    createUpdateOperationRequestMessage(ref batchWriter, changes[i], tableName, headers);
                }
                batchWriter.WriteEndChangeset();
            }
            
            batchWriter.WriteEndBatch();
            batchWriter.Flush();
            odataHttpRequest.GetStream().Seek(0, SeekOrigin.Begin);

            HttpResponseMessage result = new HttpResponseMessage();

            using (HttpClient client = new HttpClient())
            {
                result = client.SendAsync(requestMessage).Result;
            }

            return parseResponseMessage(result);
        }
        private void createDeleteOperationRequestMessage(ref ODataBatchWriter writer, Change change, string tableName)
        {
            string id = this.getKeyType(tableName).IsString() ? "'" + change.id + "'" : change.id;
            Uri uri = new Uri(tableName + "(" + id + ")", UriKind.Relative);

            writer.CreateOperationRequestMessage("DELETE", uri);
        }
        private void createUpdateOperationRequestMessage(ref ODataBatchWriter writer, Change change, string tableName, string[] headers)
        {
            string id = this.getKeyType(tableName).IsString() ? "'" + change.id + "'" : change.id;
            Uri uri = new Uri(tableName + "(" + id + ")", UriKind.Relative);
            
            var updateOperaitonMessage = writer.CreateOperationRequestMessage("PATCH", uri);
            updateOperaitonMessage.SetHeader("Content-Type", "application/json");
             

            using (var operationMessageWriter = new ODataMessageWriter(updateOperaitonMessage))
            {
                var entityWriter = operationMessageWriter.CreateODataEntryWriter();
                var entry = new ODataEntry()
                {
                    Properties = createOperationProperties(change.data, tableName, headers),
                    TypeName = this.GetEntityTypeName(tableName)
                };
                entityWriter.WriteStart(entry);
                entityWriter.WriteEnd();
            }
        }
 public static string UpdateDataToOData(Change[] chanegs, string tableName, string[] headers)
 {
     return odataHelper.UpdateDataToOData(chanegs, tableName, headers);
 }