2
votes

After upgrading to the new storage API version 4.2, I'm getting the following warning that I'm calling obsolete methods on some of my segmented queries.

'Microsoft.WindowsAzure.Storage.Table.CloudTableClient.GetTableServiceContext()' is obsolete: 'Support for accessing Windows Azure Tables via WCF Data Services is now obsolete. It's recommended that you use the Microsoft.WindowsAzure.Storage.Table namespace for working with tables.'

So far I haven't been able to figure out how to achieve this on the new API, and no examples have been put out that I have been able to find. The legacy code still runs fine, but if the new API supports something better I'd love to check it out and get rid of this warning. Could someone point me in the right direction on how a segmented query like this would look using the new API?

Here is what my code currently looks like with the warning:

public AzureTablePage<T> GetPagedResults<T>(Expression<Func<T, bool>> whereCondition, string ContinuationToken, int PageSize, string TableName) {
    TableContinuationToken token = GetToken(ContinuationToken);

    var query = AzureTableService.CreateQuery<T>(TableName).Where(whereCondition).Take(PageSize).AsTableServiceQuery(AzureTableClient.GetTableServiceContext());
    var results = query.ExecuteSegmented(token, new TableRequestOptions() { PayloadFormat = TablePayloadFormat.JsonNoMetadata });
    if (results.ContinuationToken != null) {
        return new AzureTablePage<T>() { Results = results.ToList(), HasMoreResults = true, ContinuationToken = string.Join("|", results.ContinuationToken.NextPartitionKey, results.ContinuationToken.NextRowKey) };
    } else {
        return new AzureTablePage<T>() { Results = results.ToList(), HasMoreResults = false };
    }
}
public TableServiceContext AzureTableService {
    get {
        var context = AzureTableClient.GetTableServiceContext();
        context.IgnoreResourceNotFoundException = true;
        return context;
     }
}
public CloudTableClient AzureTableClient {
    get {
        return mStorageAccount.CreateCloudTableClient();
    }
}

Solution

For anyone with the same question, here is the updated code.

    /* Add the following Using Statement */
    using Microsoft.WindowsAzure.Storage.Table.Queryable;

    public AzureTablePage<T> GetPagedResults<T>(Expression<Func<T, bool>> whereCondition, string ContinuationToken, int PageSize, string TableName) where T : class, ITableEntity, new() {
        TableContinuationToken token = GetToken(ContinuationToken);
        var query = AzureTableClient.GetTableReference(TableName).CreateQuery<T>().Where(whereCondition).Take(PageSize).AsTableQuery();
        var results = query.ExecuteSegmented(token, new TableRequestOptions() { PayloadFormat = TablePayloadFormat.JsonNoMetadata });
        if (results.ContinuationToken != null) {
        return new AzureTablePage<T>() { Results = results.ToList(), HasMoreResults = true, ContinuationToken = string.Join("|", results.ContinuationToken.NextPartitionKey, results.ContinuationToken.NextRowKey) };
    } else {
        return new AzureTablePage<T>() { Results = results.ToList(), HasMoreResults = false };
    }
}
1

1 Answers

1
votes

Please see the Tables Deep Dive blog post that we published when we first introduced the new Table Service Layer. If you need LINQ support, please also see the Azure Storage Client Library 2.1 blog post.

We strongly recommend upgrading to Table Service Layer, because it is optimized for NoSQL scenarios and therefore provides much better performance.