[英]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.我有一个 Azure 表,其中分区键是登录网站的用户的配置文件 ID,因此如果我有用户 ID 列表,我需要获取表中是否有具有该 ID 的分区键。 I want to return a list of ids(partition keys) that were found.我想返回一个找到的 id(分区键)列表。
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如果需要,我可以移动到 Sql Server 而不是 Azure 存储表
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<T>()
可能更容易,这将允许您编写 LINQ 查询:
_cloudTable.CreateQuery<ConnectionEntity>()
.AsQueryable()
.Where(w => w.PartitionKey == "1"
|| w.PartitionKey == "2"
|| w.PartitionKey == "3");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.