简体   繁体   中英

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

I'm pretty lost as to how to implement this method in Azure Table Storage. (Notice: I'm pretty new to it)

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

I'm getting an error when executing the query.

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

Here's my ConnectionEntity.

public class ConnectionEntity:TableEntity
{
    public ConnectionEntity()
    {

    }

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

Is it possible to do a Contains operator? I can't seem to find the documentation on such a query. Should I consider making a batch query on the partition key?

Looking at your code I think the only way to do what you are doing is to read on all the records of that type and do your LINQ queries against the local collection. As long as you have less then a few thousand records of this type this will be very fast, and depending on how often those records are modified you could make subsequent queries extremely fast with some sort of local cache. If you have too many records of this type for this to be feasible you might need to reconsider your partitioning strategy, or the design of this portion of your app, such that it can query smaller subsets of data, perhaps by some partition key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM