Archives For Descending

Windows Azure Table Storage stores Entities in ascending order based on the Row Key. In logs and historical data it can be useful to inverse the sort order. This allows us to take the 100 most recent additions to the Table Partition without having to do any manipulations like skipping or filtering Entities.

One way to do this, is to take the max date from the DateTime object and to subtract the current DateTime. Chances that collisions can occur are slim. But to make sure they don’t occur, I add a GUID to the end of the subtraction result.

public class Entity : TableEntity
  public Entity(string partitionKey)
      PartitionKey = partitionKey;
      var inverseTimeKey = DateTime
      RowKey = string.Format("{0}-{1}",

  public Entity()

  // ...  your properties