6
\$\begingroup\$

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

asked May 16, 2015 at 19:23
\$\endgroup\$
1
  • 2
    \$\begingroup\$ There's not a ton of code here to critique, but what I'm seeing here looks fine to me, no major errors jump out at me, and you're using var when you should, although one might argue that you shouldn't be using it for var dynamicTableEntities =... because the type if not obvious from the right hand side of that expression. \$\endgroup\$ Commented May 27, 2015 at 9:17

2 Answers 2

4
\$\begingroup\$

If I remember correctly, accessing a row by PartitionKey and RowKey is built to be the fastest operation you can do on an Azure Table Storage. The performance drawback of using a DynamicTableEntity probably isn't worth it unless the returned entity is really big.

I feel like you should stick to the Retrieve, but there's no better way to be sure than to profile both your solutions for performance to see which is better with your data.

Because there's nothing else to say about your code, from what I know, you have the 2 existing solutions in your hand. Figure the best one now :)

answered Oct 29, 2015 at 15:35
\$\endgroup\$
1
\$\begingroup\$

You should try solve this using standard TableOperation.Retrieve, but this time specified columns argument to empty list ( new List() ) or a single column ("RowKey"). This will not return the entire entity.

answered Aug 22, 2016 at 11:31
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to code review. You can probably improve your answers and get points for your answers by reading this help page codereview.stackexchange.com/help/how-to-answer \$\endgroup\$ Commented Aug 22, 2016 at 11:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.