0

My table structure has a Partition key, Row key, and a column containing JSON data. I want to query the table based on the partition key and a particular value from the JSON data.

Sample JSON Data:

{"ConsumerId":"7","value01":"850.58"}

The query I have created is

var query = new TableQuery<CloudModelDetail>().Where(TableQuery.CombineFilters(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, retailerReferenceId),
            TableOperators.And, TableQuery.GenerateFilterCondition("CloudModelJsonData","Contains", consumerId)));

But it is not giving me the desired results. Can anyone help me with the correct query?

tRuEsAtM
  • 3,517
  • 6
  • 43
  • 83
  • 1
    If you are already working with json objects you may want to consider Document DB. I believe it should be possible to query in document db by a json property. – Dogu Arslan Mar 09 '17 at 11:02

1 Answers1

2

Table Storage doesn't support wildcard matching like Contains, unfortunately. (See https://learn.microsoft.com/en-us/rest/api/storageservices/fileservices/query-operators-supported-for-the-table-service)

You can consider using CompareTo, which can act like StartsWith, as an inequality matcher - but this will only work if your JSON data always starts with {"ConsumerId":"value",

Better yet - add ConsumerId as an additional field, or rethink the partition and row key structure to make use of composite keys that include the consumer ID, which should also help performance.

gwcodes
  • 5,632
  • 1
  • 11
  • 20