Querying Windows Azure Table Storage with multiple query criteria

前端 未结 2 1096
借酒劲吻你
借酒劲吻你 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:19

    This is what I am using as a quick check for the range of uploaded records.

            .....
    
            Dictionary retrievedRecords = new Dictionary();
            int i = 0;
    
            StorageCredentials creds = new StorageCredentials(accountName, accountKey); // table storage name, Azure provided KEY1 string
            CloudStorageAccount storageAccount = new CloudStorageAccount(creds, useHttps: true);
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
    
            CloudTable table = tableClient.GetTableReference(tableName); // your table name
    
            // filters
            string filter1 = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionName); // partitionName i.e.: "myTablePartition1"
            string filter2 = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, recordStart); // recordStart i.e.: "123"
            string filter3 = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThan, recordEnd); // recordEnd i.e.: "567"
    
            string filterRange = TableQuery.CombineFilters(filter2, TableOperators.And, filter3);
    
    
            // query.
            TableQuery rangeQuery = new TableQuery().Where(
    
                TableQuery.CombineFilters(filter1, TableOperators.And, filterRange)
            );
    
            // Loop & store
            foreach (CustomerEntity entityT in table.ExecuteQuery(rangeQuery))
            {
                string PartitionKey = entityT.PartitionKey;
                string RowKey = entityT.RowKey;
                string col1 = entityT.col1;
                string col2  = entityT.col2;
                string col3  = entityT.col3;
                string col4  = entityT.col4;
                string col5  = entityT.col5;
                string col6  = entityT.col6;
    
                string[] row = new string[] { PartitionKey, RowKey, col1 , col2, col3, col4, col5, col6 };
                retrievedRecords.Add(i, row);
    
                i++;
            }
    
            return retrievedRecords;
    
    // function end or else.....
    ....
    

提交回复
热议问题