多种过滤条件Azure表存储 [英] Multiple filter conditions Azure table storage

查看:60
本文介绍了多种过滤条件Azure表存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Azure表存储上设置多个过滤器?

How can I set multiple filters on a Azure Table Storage?

这是我尝试过的:

string partitionFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "partition1");
string date1 = TableQuery.GenerateFilterCondition("Date", QueryComparisons.GreaterThanOrEqual, "31-8-2013T14:15:14Z");
string date2 = TableQuery.GenerateFilterCondition("Date", QueryComparisons.LessThanOrEqual, "31-8-2013T14:15:14Z");
string finalFilter = TableQuery.CombineFilters(partitionFilter, TableOperators.And, date1);

这不起作用,因为TableQuery.CombineFilters()仅接受3个参数.而且第二个日期我需要一个额外的参数.

This doesn't work because TableQuery.CombineFilters() only takes 3 parameters. And I need an extra parameter for the 2nd date.

第二次尝试:

string filter = "PartitionKey eq 'partition1' and Date ge datetime'31-8-2013T14:15:14Z' and Date lt datetime'31-8-2013T14:19:10Z'";
TableQuery<CustomEntity> query = new TableQuery<CustomEntity>().Where(filter).Take(5);

这将返回400 bad request.但是,如果我删除了"datetime",它将运行但不返回任何结果,而应返回几百条记录.

This returns 400 bad request. But if I remove the 'datetime' it runs but returns no results while it should return a few 100 records.

根据msdn中的文档,日期时间应该是这样进行格式化.

According to this doc from msdn, that is how datetimes should be formatted.

我的结果应该是两个日期之间的所有记录.

My result should be all records that are between two dates.

我该如何进行这项工作?

How can I make this work?

推荐答案

首先用一个日期过滤器和"分区过滤器,然后用另一个日期过滤器和"中间结果.

First "and" your partition filter with one of the date filters, then "and" the intermediate result with the other date filter.

string date1 = TableQuery.GenerateFilterConditionForDate(
                   "Date", QueryComparisons.GreaterThanOrEqual,
                   DateTimeOffsetVal);
string date2 = TableQuery.GenerateFilterConditionForDate(
                   "Date", QueryComparisons.LessThanOrEqual,
                   DateTimeOffsetVal);
string finalFilter = TableQuery.CombineFilters(
                        TableQuery.CombineFilters(
                            partitionFilter,
                            TableOperators.And,
                            date1),
                        TableOperators.And, date2);

这篇关于多种过滤条件Azure表存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆