After upgrading to Azure Storage 4 I noticed that a lot of the old methods for getting continuation tokens no longer work. I wasn't able to find a very clean work around so instead I cheated a little bit.

TableQuery via the CreateQuery<> method doesn't have any way to get the continuation token from what I've been able to find. So instead of relying on the response to include a token I made my own.

The trick with the token is that it gives you the partition key and the row key of the next entry. So the way I cheated was I simply grabbed one more entry then I actually wanted.

var posts = (from entity in AzureTableStorage.PostTable.CreateQuery<Post>()
             where entity.StatusCode == 1
             select entity).Take(11).ToList();

Using this I then made a token that I passed to the view via the ViewBag.

if (posts.Count > 10)
    ViewBag.Continuation = posts.Last().RowKey + "|" + posts.Last().PartitionKey;
     ViewBag.Continuation = "";

Using ViewBag.Continuation I made a link, just something simple such as /?next=@ViewBag.Continuation.

Then I added a string next = "" to my method along with a check to see if I needed to use it or not.

    // Lookup from above
    var continuation = next.Split(new[] { '|' });
    var token = new TableContinuationToken { NextRowKey = nextRow, NextPartitionKey = nextPartition };
    var posts = AzureTableStorage.PostTable.CreateQuery<Post>()
                .Where(m => m.StatusCode == 1)

I don't think this is the most elegant solution. I saw suggestions of storing the continuation token in the users Session and then faking the "page" as some int but I was a little worried about the likes of Bing and Google to take that the wrong way.

To see this in action just scroll to the bottom of the home page.

Obviously because I'm forced to grab 11 entries instead of 10 there is a performance hit, though in this case it's so minimal I'm happy to live with it. If anyone knows of a better method to this issue I am all ears.

About Author

Siva Katir

Siva Katir

Principal Software Engineer working on PlayFab at Microsoft in Redmond, Washington.