Azure的表的存储警告 - WCF数据服务已经过时 [英] Azure Table Storage Warning - WCF Data Services obsolete

查看:336
本文介绍了Azure的表的存储警告 - WCF数据服务已经过时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到新的存储API 4.2版本后,我得到以下警告,我号召我的一些分段查询过时的方法。


  

Microsoft.WindowsAzure.Storage.Table.CloudTableClient.GetTableServiceContext()'
  已经过时了:支持通过WCF数据访问Windows Azure的表
  服务现在已经过时。我们建议您使用
  Microsoft.WindowsAzure.Storage.Table命名空间与工作
  表。


到目前为止,我一直无法弄清楚如何实现这一目标的新的API,也没有例子已经被扑灭,我已经能够找到。传统code依然运行良好,但如果新的API支持更好的东西我很想看看,远离警告。有人能指出我如何像这样的分段查询看起来使用新的API正确的方向?

下面是我的code目前看起来像一个警告:

 公共AzureTablePage< T> GetPagedResults< T>(防爆pression<&Func键LT; T,BOOL>> whereCondition,串ContinuationToken,诠释每页,字符串表名){
    TableContinuationToken令牌=为gettoken(ContinuationToken);    VAR的查询= AzureTableService.CreateQuery<T>(TableName).Where(whereCondition).Take(PageSize).AsTableServiceQuery(AzureTableClient.GetTableServiceContext());
    VAR的结果= query.ExecuteSegmented(令牌,新TableRequestOptions(){PayloadFormat = TablePayloadFormat.JsonNoMetadata});
    如果(results.ContinuationToken!= NULL){
        返回新AzureTablePage&LT; T&GT;(){结果= results.ToList(),HasMoreResults = TRUE,ContinuationToken =的string.join(|,results.ContinuationToken.NextPartitionKey,results.ContinuationToken.NextRowKey)};
    }其他{
        返回新AzureTablePage&LT; T&GT;(){结果= results.ToList(),HasMoreResults = FALSE};
    }
}
公共TableServiceContext AzureTableService {
    获得{
        VAR上下文= AzureTableClient.GetTableServiceContext();
        context.IgnoreResourceNotFoundException = TRUE;
        返回语境;
     }
}
公共CloudTableClient AzureTableClient {
    获得{
        返回mStorageAccount.CreateCloudTableClient();
    }
}

解决方案

对于同一个问题的人,这里是更新code。

  / *添加下面的using语句* /
    使用Microsoft.WindowsAzure.Storage.Table.Queryable;    公共AzureTablePage&LT; T&GT; GetPagedResults&LT; T&GT;(防爆pression&LT; Func键&LT; T,BOOL&GT;&GT; whereCondition,串ContinuationToken,诠释每页,字符串表名),其中T:类,ITableEntity,新的(){
        TableContinuationToken令牌=为gettoken(ContinuationToken);
        VAR的查询= AzureTableClient.GetTableReference(TableName).CreateQuery<T>().Where(whereCondition).Take(PageSize).AsTableQuery();
        VAR的结果= query.ExecuteSegmented(令牌,新TableRequestOptions(){PayloadFormat = TablePayloadFormat.JsonNoMetadata});
        如果(results.ContinuationToken!= NULL){
        返回新AzureTablePage&LT; T&GT;(){结果= results.ToList(),HasMoreResults = TRUE,ContinuationToken =的string.join(|,results.ContinuationToken.NextPartitionKey,results.ContinuationToken.NextRowKey)};
    }其他{
        返回新AzureTablePage&LT; T&GT;(){结果= results.ToList(),HasMoreResults = FALSE};
    }
}


解决方案

请参见<一个href=\"http://blogs.msdn.com/b/windowsazurestorage/archive/2012/11/06/windows-azure-storage-client-library-2-0-tables-deep-dive.aspx\"相对=nofollow>表深潜博客文章我们当我们第一次推出了新的表服务层公开。如果你需要LINQ的支持,也请请参阅<一个href=\"http://blogs.msdn.com/b/windowsazurestorage/archive/2013/09/07/announcing-storage-client-library-2-1-rtm.aspx\"相对=nofollow> Azure存储客户端库2.1的博客文章。

我们强烈建议您升级到表服务层,因为它是对NoSQL的方案进行了优化,从而提供更好的性能。

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 };
    }
}

解决方案

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.

这篇关于Azure的表的存储警告 - WCF数据服务已经过时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆