Azure存储表ExecuteQuerySegmentedAsync扩展方法中的调用错误

时间:2016-07-07 18:26:17

标签: c# azure asp.net-core azure-storage azure-table-storage

以下扩展方法不会在我的ASP.NET Core项目中编译,Visual Studio会将方法ExecuteQuerySegmentedAsync作为问题突出显示。错误(在代码下面)引用了我不想要的方法签名。我想要这个here

internal static class CloudTableExtensions
{
        public static async Task<IList<DynamicTableEntity>> ExecuteQueryAsync(this CloudTable table,
            TableQuery query, CancellationToken cancellationToken = default(CancellationToken))
    {
        var items = new List<DynamicTableEntity>();
        TableContinuationToken token = null;
        do
        {
            var seg = await table.ExecuteQuerySegmentedAsync(query, token, cancellationToken);

            token = seg.ContinuationToken;
            items.AddRange(seg);


        } while (token != null && !cancellationToken.IsCancellationRequested 
             && (query.TakeCount == null || items.Count < query.TakeCount.Value));


        return items;
    }
}

错误是: Error CS0411 The type arguments for method 'CloudTable.ExecuteQuerySegmentedAsync<T, TResult>(TableQuery<T>, EntityResolver<TResult>, TableContinuationToken)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

1 个答案:

答案 0 :(得分:1)

ASP.NET Core 1.0.0的WindowsAzure.Storage 7.1.3-Preview nuget包 不包含具有此签名的ExecuteQuerySegmentedAsync函数。 也许你应该在github repo上为此创建一个问题。

否则,如果您需要传递取消令牌,则可以使用this

internal static class CloudTableExtensions
{
    public static async Task<IList<DynamicTableEntity>> ExecuteQueryAsync(this CloudTable table,
        TableQuery query, CancellationToken cancellationToken = default(CancellationToken))
    {
        var items = new List<DynamicTableEntity>();
        TableContinuationToken token = null;
        do
        {
            var seg =
                await
                    table.ExecuteQuerySegmentedAsync(query, token, new TableRequestOptions(), new OperationContext(),
                        cancellationToken);

            token = seg.ContinuationToken;
            items.AddRange(seg);


        } while (token != null && !cancellationToken.IsCancellationRequested
                 && (query.TakeCount == null || items.Count < query.TakeCount.Value));


        return items;
    }
}