I want to check as fast as possible if an entity, based on PartitionKey and RowKey, exists in an Azure Table Storage.
I can do a standard TableOperation.Retrieve and check the result, like:
TableOperation retrieveOperation = TableOperation.Retrieve<CustomerEntity>("Smith", "Ben");
TableResult retrievedResult = table.Execute(retrieveOperation);
but that would return the complete entity.
By using a DynamicTableEntity I reduce the amount of data that is returned. More code, but I assume better...
public async Task<bool> EntityExists(string partitionKey, string rowKey)
{
var tableQuery = new TableQuery<DynamicTableEntity>();
tableQuery.FilterString = TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, paritionKey),
TableOperators.And,
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, rowKey));
var dynamicTableEntities = await CloudTable.ExecuteQuerySegmentedAsync(tableQuery, null, TableRequestOptions, OperationContext);
return dynamicTableEntities.Results.Any();
}
Any suggestions/criticisms to my solution are welcome
var dynamicTableEntities =...
because the type if not obvious from the right hand side of that expression. – Nick Udell May 27 '15 at 9:17