簡體   English   中英

您如何在azure表存儲中查詢多個分區鍵?

[英]How do you query for multiple partition keys in azure table storage?

我對如何在Azure表存儲中實現此方法一無所知。 (注意:我對此很陌生)

public IList<string> GetUserConnections(int[] userIds)
{
    string[] result = userIds.Select(x => x.ToString()).ToArray();
    var queryResult = _table.CreateQuery<ConnectionEntity>().Where(n =>     result.Contains(n.PartitionKey));
    return queryResult.Select(n => n.RowKey).ToList();
}

執行查詢時出現錯誤。

An exception of type 'System.NotSupportedException' occurred in
Microsoft.WindowsAzure.Storage.dll but was not handled in user code

Additional information: The method 'Contains' is not supported

這是我的ConnectionEntity。

public class ConnectionEntity:TableEntity
{
    public ConnectionEntity()
    {

    }

    public ConnectionEntity(int userId, string connectionId)
    {
        this.PartitionKey = userId.ToString();
        this.RowKey = connectionId;
    }
}

是否可以執行“包含”運算符? 我似乎找不到此類查詢的文檔。 我應該考慮對分區鍵進行批量查詢嗎?

查看您的代碼,我認為要做的唯一方法是讀取該類型的所有記錄,並對本地集合執行LINQ查詢。 只要您擁有的這種類型的記錄少於幾千條,這將是非常快的,並且根據這些記錄被修改的頻率,您可以使用某種本地緩存非常快速地進行后續查詢。 如果您對此類型的記錄過多,那么您可能需要重新考慮您的分區策略或應用程序這一部分的設計,以便它可以通過一些分區鍵查詢較小的數據子集。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM