public void Write(string key, string value) { var batch = new TableBatchOperation(); var record = new AzureTableRecord { PartitionKey = _appName, RowKey = key, ETag = "*" }; if (value != null) { record.Value = value; batch.InsertOrMerge(record); } else { batch.Delete(record); } try { _table.ExecuteBatch(batch); } catch (StorageException) { //not ideal check. If value is null (Delete operation) and record doesn't exist //I ignore the exception as it simply says that entity doesn't exist which is fine. //I don't know how to check for the specific error code. if (value != null) { throw; } } }
public string Read(string key) { if (key == null) { return(null); } var filter = TableQuery.CombineFilters( TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, _appName), TableOperators.And, TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, key)); var query = new TableQuery <AzureTableRecord>().Where(filter); IEnumerable <AzureTableRecord> records = _table.ExecuteQuery(query); AzureTableRecord record = records?.FirstOrDefault(); return(record?.Value); }