Is there a way to get distinct PartionKeys from a Table

I don't think there is a way to retrieve all the partition keys. Here's a clever workaround, though: https://docs.microsoft.com/en-gb/archive/blogs/avkashchauhan/retrieving-partition-key-range-in-windows-azure-table-storage

To quote from Avkash's blog:

Digging further, I found there is no built in API to get a list of partition keys, instead I would have to create a solution for myself. So I end up inserting a single dummy row into each partition and when I wanted to get a list of partition keys I just query for those dummy items and they gave me the list I was looking for.

I'm certain you will already have seen this, but for others who may happen on this question, I think this is the best guide to table service functionality: http://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-tables/ with examples and links to the detailed API docs.


Create a single table to store your partitions. Partition the table by the table names you use and add an entry for each partition you create.

public class PartitionEntry : TableServiceEntity { }

tableServiceContext.AddObject("TablePartitions", new PartitionEntry
{
    PartitionKey = "<table name>",
    RowKey = "<partition key>",
});
tableServiceContext.BeginSaveChanges(SaveChangesOptions.ContinueOnError, null, null);

then just query this table to get a list of partitions. This is very manageable to me.

var tbl = tableServiceContext.CreateQuery<PartitionEntry>("TablePartitions");
return tbl.Where(i => i.PartitionKey == "<table name>")
          .Select(i => new { PartitionKey = i.RowKey, });

I bet this could be optimized.