简体   繁体   中英

How can I query from a list of partition keys in Azure table storage

I have an Azure table where the partition key is the profile id of a user logged into the website, so if I have a list of user ids I need to fetch if there is a partition key in the table with that id. I want to return a list of ids(partition keys) that were found.

I can't seem to find any good info online, that says I can do this easily!

If needed I can just move to Sql Server instead of Azure Storage Tables

I want to do something like this

 var query = new TableQuery<ConnectionEntity>()
.Where(TableQuery.GenerateFilterCondition("PartitionKey" , QueryComparisons.Equal, "1 or 3 or 4"));

 var queryResult = table.ExecuteQuery(query).ToList();

You want to combine multiple filters.

var filterOne = TableQuery.GenerateFilterCondition("PartitionKey" , QueryComparisons.Equal, "1");

var filterTwo = TableQuery.GenerateFilterCondition("PartitionKey" , QueryComparisons.Equal, "2");

var filterThree = TableQuery.GenerateFilterCondition("PartitionKey" , QueryComparisons.Equal, "3");

var combinedFilters = TableQuery.CombineFilters(
                    TableQuery.CombineFilters(
                        filterOne,
                        TableOperators.Or,
                        filterTwo),
                    TableOperators.And, filter3);

var query = new TableQuery<ConnectionEntity>()
    .Where(combinedFilters);

Alternatively, it might be easier to use CreateQuery<T>() against your CloudTable , which will let you write LINQ queries:

_cloudTable.CreateQuery<ConnectionEntity>()
    .AsQueryable()
    .Where(w => w.PartitionKey == "1" 
        || w.PartitionKey == "2" 
        || w.PartitionKey == "3");

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