Reputation: 1251
I want to query the table by property value. So lets say I have the following table
I want to create a query where I give me all records where PartitionKey = section3 FirstName = value3 Timestamp : last 12 hrs
I have the following code so far:
// Retrieve the storage account from the connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the table client.
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
// Create the CloudTable object that represents the "asometrichub" table.
CloudTable table = tableClient.GetTableReference("customer");
TableQuery rangeQuery = new TableQuery().Where(
TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "section3"),
TableOperators.And,
TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.GreaterThanOrEqual, DateTime.UtcNow.AddHours(-12))));
Not sure how I filter on the FirstName=value3. Thank you!
Upvotes: 0
Views: 127
Reputation: 6467
TableQuery.CombineFilters()
can be called in a nested way:
// Retrieve the storage account from the connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the table client.
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
// Create the CloudTable object that represents the "asometrichub" table.
CloudTable table = tableClient.GetTableReference("customer");
string combinedFilter = TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "section3"),
TableOperators.And,
TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.GreaterThanOrEqual, DateTime.UtcNow.AddHours(-12)));
combinedFilter = TableQuery.CombineFilters(
combinedFilter,
TableOperators.And,
TableQuery.GenerateFilterCondition("FirstName", QueryComparisons.Equal, "value3"));
TableQuery rangeQuery = new TableQuery().Where(combinedFilter);
Upvotes: 1