【问题标题】:Azure Table QuerySegmented no returnAzure Table QuerySegmented 不返回
【发布时间】:2013-03-11 11:11:18
【问题描述】:

我正在尝试从 AzureTable 中提取一组实体,并使用以下代码对其进行查询。

string partitionKey = string.Format(CultureInfo.InvariantCulture, "{0:d20}", accountId);
string rowKeyStart = string.Format(CultureInfo.InvariantCulture, "{0}:g", work.lead.id);
string rowKeyEnd = string.Format(CultureInfo.InvariantCulture, "{0}:h", work.lead.id);

var context = table.ServiceClient.GetTableServiceContext();
var query = context.CreateQuery<LinkedInPostEntity>(table.Name)
        .Where(w => w.PartitionKey == partitionKey && w.RowKey.CompareTo(rowKeyStart) > 0 && w.RowKey.CompareTo(rowKeyEnd) <= 0)
        .AsTableServiceQuery(context);

List<PostEntity> postsForLead = new List<PostEntity>();
TableContinuationToken continuation = null;

do
{
    TableQuerySegment<PostEntity> segment = await AzureHelper.QuerySegmented(query, continuation);
    postsForLead.AddRange(segment.Results);
    continuation = segment.ContinuationToken;
} while (continuation != null);

table 是 CloudTable 的一个实例,accountId 是一个 int,work.lead.id 是一个字符串。我想提取所有具有以 work.lead.id:g 为前缀的 RowKey 并后跟字符串 id 的实体。我觉得这段代码应该可以工作,但它挂在await 上,从未完成 QuerySegmented 给出的Task

我的想法可能是查询格式不正确,但我不确定如何或为什么。

顺便说一句,我是新发帖者,所以如果我忘记了任何重要信息或无论如何都可以帮助澄清,请告诉我。

编辑:这里有一个非常相似的代码,它在一个类似(虽然不同)的表上被调用,该表具有不同的 id 方案。我需要使用我正在使用的 api 给我的 id 方案,所以我不认为在进入之前重新格式化它是一种选择。两者之间的唯一区别是查询,所以我觉得我的查询是罪魁祸首。有什么想法吗?

string partitionKey = string.Format(CultureInfo.InvariantCulture, "{0:d20}", accountId);
string rowKeyStart = string.Format(CultureInfo.InvariantCulture, "{0}:{1:d20}", work.ScreenName, (long)0);
string rowKeyEnd = string.Format(CultureInfo.InvariantCulture, "{0}:{1:d20}", work.ScreenName, long.MaxValue);

var context = table.ServiceClient.GetTableServiceContext();
var query = context.CreateQuery<TweetEntity>(table.Name)
        .Where(w => w.PartitionKey == partitionKey && w.RowKey.CompareTo(rowKeyStart) >= 0 && w.RowKey.CompareTo(rowKeyEnd) <= 0)
        .AsTableServiceQuery(context);

List<TweetEntity> tweetsForLead = new List<TweetEntity>();

TableContinuationToken continuation = null;

do
{
    TableQuerySegment<TweetEntity> segment = await AzureHelper.QuerySegmented(query, continuation);
    tweetsForLead.AddRange(segment.Results);
    continuation = segment.ContinuationToken;
} while (continuation != null);

【问题讨论】:

    标签: azure azure-storage azure-table-storage


    【解决方案1】:

    我的蜘蛛侠告诉我,您正在调用此方法,然后从 ASP.NET 或 UI 上下文对返回的任务调用 WaitResultIf you do this, you'll deadlock,正如我在博客中解释的那样。

    【讨论】:

    • 嗯似乎这可能是问题所在!奇怪,因为它适用于不同类型的查询,让我在将其标记为正确之前深入研究它。非常感谢!
    • 嗯不幸的是它似乎没有解决问题。我有机会阅读您的博客文章,似乎上下文问题仅适用于 UI 应用程序。这段代码在 Azure Worker Role 中运行,所以我认为它不会成为同样问题的受害者。
    • 在这种情况下,你能发布一个小而完整的复制品吗?
    猜你喜欢
    • 1970-01-01
    • 2021-01-06
    • 1970-01-01
    • 2016-04-02
    • 1970-01-01
    • 2016-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多