Azure Table Storage Warning - WCF Data Services obsolete

假如想象 提交于 2020-01-04 21:34:56

问题


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:


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.



来源:https://stackoverflow.com/questions/25532131/azure-table-storage-warning-wcf-data-services-obsolete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!