TableBatchOperation batchOperation = new TableBatchOperation(); MyEntity entity = new MyEntity("partitionKey", "rowKey") { Property1 = "Value1", Property2 = "Value2" }; // Insert the entity using InsertOrMerge operation batchOperation.InsertOrMerge(entity); // Execute the batch operation await table.ExecuteBatchAsync(batchOperation);
TableBatchOperation batchOperation = new TableBatchOperation(); MyEntity entity = new MyEntity("partitionKey", "rowKey") { Property1 = "New Value1", Property2 = "New Value2" }; // Insert or update the entity using InsertOrMerge operation batchOperation.InsertOrMerge(entity); // Execute the batch operation await table.ExecuteBatchAsync(batchOperation);In this example, we create a new instance of the MyEntity class and set its properties with the updated values. Then we add it to the TableBatchOperation using InsertOrMerge, which will insert a new entity if it does not exist, or update an existing entity with the same partition key and row key if it exists. In summary, TableBatchOperation.InsertOrMerge is a useful method that simplifies the process of inserting new entities or updating existing ones in Azure Table Storage using a batch operation. It is part of the Microsoft.Azure.Cosmos.Table library.