Posts

Showing posts from January, 2014

Showing rows in reverse chronological order using Windows Azure Table Storage a.k.a order by descending

We can set the RowKey to be a fixed length string equivalent of DateTime.MaxValue.Ticks -  DateTime.UtcNow.Ticks. This allows the RowKey to sort the items by an offsetted time from newest items to older items. string rowKeyToUse = string.Format("{0:D19}",  DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks); This works because when you move ahead in time, DateTime.UtcNow.Ticks increases in value - thereby the difference between max value and this value decreases - hence these rows will go to the top. let us assume that a blog can be rated from 0-5 and we want to ensure that blogs are listed such that they are sorted by   (Rating   in desc order, Created time in desc order).    This means that they are storted first by rating, and then sorted within each rating by the created time.     Here we can set the row key to <Rating>+<Ticks to force items to be sorted from newest to older items>. So taking the same example as above, in the two blogs above, let us assume