Skip to content

Instantly share code, notes, and snippets.

@vitormeriat
Last active May 16, 2022 15:33
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save vitormeriat/a0f76e4fb7de5c689130628941ff5845 to your computer and use it in GitHub Desktop.
Check if an entity exists in a Azure Table Storage
public async Task<bool> EntityExists(string partitionKey, string rowKey)
{
var tableQuery = new TableQuery<DynamicTableEntity>();
tableQuery.FilterString = TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey),
TableOperators.And,
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, rowKey));
var dynamicTableEntities = await CloudTable.ExecuteQuerySegmentedAsync(tableQuery, null, TableRequestOptions, OperationContext);
return dynamicTableEntities.Results.Any();
}
@winperec
Copy link

winperec commented Nov 5, 2020

It looks easier

public async Task<bool> EntityExists(string partitionKey, string rowKey)
{ 
   var result = await CloudTable.ExecuteAsync(TableOperation.Retrieve<TableEntity>(partitionKey, rowKey)); 
   return result.Result != null; // or result.HttpStatusCode != 404
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment