public async Task InsertOrReplace(PersonEntity person) { await DeleteEntityIfExists(person); var tableName = $"{_tableNamePrefix}{person.EyeColor}"; var table = _tableClient.GetTableReference(tableName); await table.CreateIfNotExistsAsync(); var insertOperation = TableOperation.Insert(person); await table.ExecuteAsync(insertOperation); }
private async Task DeleteEntityIfExists(PersonEntity person) { var tables = await GetTables(); var query = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, person.RowKey); foreach (var table in tables) { var queryResult = await table.ExecuteQuerySegmentedAsync(new TableQuery <PersonEntity>().Where(query), null); var personToDelete = queryResult.FirstOrDefault(); if (personToDelete != null) { var deleteOperation = TableOperation.Delete(personToDelete); await table.ExecuteAsync(deleteOperation); } } }