I am trying to delete row from azure storage filter by only rowkey value. But I dont see any overload for delete operation where we can filter with only rowkey. Is there any alternative option to delete row from azure storage table for records with specific rowkey?
RemoveEntityByRowKey('123456');
public static void RemoveEntityByRowKey(string myRowKey)
{
try
{
CloudTable table = _tableClient.GetTableReference("MyAzureTable");
TableOperation delteOperation = TableOperation.Delete(myRowKey);
table.Execute(delteOperation);
}
catch (Exception ex)
{
LogError.LogErrorToAzure(ex);
throw;
}
}
In order to delete an entity, you would need both PartitionKey
and RowKey
(Delete Entity REST API
). So what you would need to do is first fetch the entity with matching RowKey
. Once you have fetched this entity, you should be able to call TableOperation.Delete
as mentioned in the answers.
However, fetching entity by RowKey
is not recommended because it will do a Full Table Scan. It may not be a problem if your table size is small but would be an issue where your table contains large number of entities. Furthermore, a RowKey
is unique in a Partition
i.e. in a table there can be only one entity with a PartitionKey
/RowKey
combination. In other words, you can potentially have entities with same RowKey
in different Partitions
. So when you fetch entities by RowKey
only, you may get more than one entity back. You need to ensure that you're deleting correct entity.