【问题标题】:Compiler error when combining Linq + "RangeVariables" + TPL + DynamicTableEntity组合 Linq + "RangeVariables" + TPL + DynamicTableEntity 时出现编译器错误
【发布时间】:2012-11-26 04:22:57
【问题描述】:

我正在查看 Microsoft 提供的示例 "Process Tasks as they Finish",并将该 TPL 示例改编为 Azure 存储。

我遇到的问题标记在下面,变量domainData 报告编译器中的错误:Unknown method Select(?) of TableQuerySegment<DynamicTableEntity>(已删除完全限定的命名空间)

我还收到以下错误DynamicTableEntity domainData \n\r Unknown type of variable domainData

      /// if you have the necessary references the following most likely should compile and give you same error

            CloudStorageAccount acct = CloudStorageAccount.DevelopmentStorageAccount;

            CloudTableClient client = acct.CreateCloudTableClient();
            CloudTable tableSymmetricKeys = client.GetTableReference("SymmetricKeys5");

            TableContinuationToken token = new TableContinuationToken() { };
            TableRequestOptions opt = new TableRequestOptions() { };
            OperationContext ctx = new OperationContext() { ClientRequestID = "ID" };
            CancellationToken cancelToken = new CancellationToken();

            List<Task> taskList = new List<Task>();

            var task2 = tableSymmetricKeys.CreateIfNotExistsAsync(cancelToken);
            task2.Wait(cancelToken);


            int depth = 3;
            while (true)
            {
                Task<TableQuerySegment<DynamicTableEntity>> task3 = tableSymmetricKeys.ExecuteQuerySegmentedAsync(query, token, opt, ctx, cancelToken);

                // Run the method
                task3.Wait();

                 Console.WriteLine("Records retrieved in this attempt = " + task3.Result.Count());// + " | Total records retrieved = " + state.TotalEntitiesRetrieved);



        // HELP! This is where I'm doing something the compiler doesn't like
        //
                IEnumerable<Task<int>> getTrustDataQuery =
                              from domainData in task3.Result select QueryPartnerForData(domainData, "yea, search for this.", client, cancelToken);

                // Prepare for next iteration or quit
                if (token == null)
                {
                    break;
                }
                else
                {
                    token = task3.Result.ContinuationToken;

                    // todo: persist token  token.WriteXml()
                }
            }




    //....

  private static object QueryPartnerForData(DynamicTableEntity domainData, string p, CloudTableClient client, CancellationToken cancelToken)
    {
        throw new NotImplementedException();
    }

【问题讨论】:

    标签: linq asynchronous azure task-parallel-library azure-storage


    【解决方案1】:

    您的代码缺少查询。为了测试代码,我创建了以下查询:

    TableQuery<DynamicTableEntity> query = new TableQuery<DynamicTableEntity>()
        .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "temp"));
    

    我还添加了方法QueryPartnerForData,它什么都不做(只是返回null)并且一切正常。那么可能是QueryPartnerForData 方法的问题?找出实际错误的最佳方法是在这里和那里设置断点。

    StackOverflowException 通常意味着您陷入了无限循环。通过断点运行几次,看看你的代码卡在哪里。难道是QueryPartnerForData调用了另一个方法,而另一个方法又调用了QueryPartnerForData

    【讨论】:

    • 我会澄清一下:代码不会编译 Linq 语句,并且 StackOverflow 注释是对 www.stackoverflow.com 的引用(不是例外)。
    • 看来我遇到了 Linq 和 RangeVariable: DynamicTableEntity 的问题
    • 奇怪,我刚刚删除了该行并重新输入,错误就消失了。 Control-Z 和重做没有暴露任何差异。有趣的 IDE(或插件)惹恼了我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    • 2012-12-21
    • 1970-01-01
    相关资源
    最近更新 更多