Create and query Table Storage entities in chronological order

added by sandrino
12/20/2012 12:46:08 AM


Windows Azure Table Storage is a great way to store your data: partitions make it easy to scale and it’s very cheap (as opposed to Windows Azure SQL Database). But there are some downsides of choosing Table Storage: no indexes (except for the partition and row key), no full text search and no sorting. Well, actually you get sorting. The entities are stored in lexicographical order and this is based on the row key. Steve Marx wrote a blog post about this (over 4 years ago!): Using Numbers as Keys in Windows Azure. He generates a row key which is based on the DateTime.UtcNow.Ticks to sort items in reverse chronological order. This is a great way to (ab)use lexicographical order of entities to make sure your items are sorted by newest first/oldest first. And many applications you build often need this: a blog where you want the newest posts first, a CMS that should show the newest articles first, a todo list which shows the oldest items first, …