saon
saon

Reputation: 741

How to write combined query from azure table storage?

I am trying to query from a table so that the name and partition key (combined) unique. I am doing this right now:

public Spec(string name)
{
    Query = new TableQuery<TableEntity>()
        .Where(TableQuery.GenerateFilterCondition(nameof(table.Name), QueryComparisons.Equal, name));
}

but I also need to check partition key exists withing this name. So need to query the table along with the partition key and the name. Can anybody help with this? How to query these as combined query.

Upvotes: 0

Views: 449

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136136

Please try something like below:

public Spec(string name)
{
    var filterCondition1 = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "PartitionKeyValue");
    var filterCondition2 = TableQuery.GenerateFilterCondition(nameof(table.Name), QueryComparisons.Equal, name);
    Query = new TableQuery<TableEntity>()
        .Where(TableQuery.CombineFilters(filterCondition1, "AND", filterCondition2));
}

Upvotes: 1

Related Questions