This may be somewhat related to this SO question How to perform a case-sensitive LINQ query in Azure?. However I'm using Storage Client 3.0, not the linq queries and the TableStorageContext in that question.
I have a table storage entity called Account that has a string property for email address. The email property is not a partition key or a row key.
I want to search for an entity with a matching email address in a case-insensitive way, such that a search for "[email protected]" returns "[email protected]", etc.
My code looks something like this:
TableQuery<Account> rangeQuery = new TableQuery<Account>().Where(
TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "account"),
TableOperators.And,
TableQuery.GenerateFilterCondition("Email", QueryComparisons.Equal, email)));
var results = accountsTable.ExecuteQuery(rangeQuery).ToList();
Is there a way to perform a case insensitive query using the tableQuery class, or is there another approach? Should I just concentrate on data grooming and ensure that all data is forced to a consistent case?
Azure table storage is being deprecated in favor of Azure Cosmos DB. Azure Cosmos DB offers many advantages over Azure table storage, such as: -Azure Cosmos DB is scalable.
Yes, the API for Table supports OData query and LINQ query.
The key in an Azure Table Storage table comprises two elements. The partition key that identifies the partition containing the row, and a row key that is unique to each row in the same partition. Items in the same partition are stored in row key order. Rows that share the same partition key will be stored together.
To answer your question about doing case-insensitive search, it is not possible to do so with Windows Azure Table Storage.
One way is the one you suggested i.e. doing data grooming and store all in either lower or upper case.
Other approach would be to download the data on the client side and then doing case sensitive search on the data which is fetched on the client. 2nd approach may be feasible for smaller data sets but would not be practical if the data set is much bigger.
Searching for anything that is not the leftmost part of the partition+row key would result in a table scan.
One approach would be to store, in another table, the email in lower or upper case so that it can be searched without doing a table scan.
In your example say,
Partition key = test.com
Row key = bob
would work quite well and give you many querying options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With