Querying Windows Azure Table Storage with multiple query criteria

前端 未结 2 1092
借酒劲吻你
借酒劲吻你 2020-12-18 21:34

I\'m trying to query a table in Windows Azure storage and was initially using the TableQuery.CombineFilters in the TableQuery().Where<

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-18 22:32

    A combined filter can then be combined with another filter, repeating as many times as necessary. See the example "Sample – Query all entities with a PartitionKey=”SamplePK” and RowKey greater than or equal to “5”" at https://docs.microsoft.com/en-us/archive/blogs/windowsazurestorage/windows-azure-storage-client-library-2-0-tables-deep-dive#querying.

    
    string pkFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "samplePK");
    
    string rkLowerFilter = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, "5");
    
    string rkUpperFilter = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThan, "10");
    
    // Note CombineFilters has the effect of "([Expression1]) Operator (Expression2]), as such passing in a complex expression will result in a logical grouping.
    string combinedRowKeyFilter = TableQuery.CombineFilters(rkLowerFilter, TableOperators.And, rkUpperFilter);
    
    string combinedFilter = TableQuery.CombineFilters(pkFilter, TableOperators.And, combinedRowKeyFilter);
    
    // OR 
    string combinedFilter = string.Format("({0}) {1} ({2}) {3} ({4})", pkFilter, TableOperators.And, rkLowerFilter, TableOperators.And, rkUpperFilter);
    TableQuery query = new TableQuery().Where(combinedFilter);
    

提交回复
热议问题