Windows Azure Tables, querying using Contains
I'm trying to implement a query for one of my Azure Tables, the query should retrieve all files that contain the input string.
I've tried using string.contains() but this isn't supported by Azure, I've also tried string.startswith() this also isn't supported.
What I'm wondering is if there is a way to do this in Azure Tables. I'm storing file information in the tables and the partition key is the virtual path of the item stored.
e.g. Images_Jpg_Image1.jpg would be a partition key for one of the files, i've used '_' because Azure won't allow '/' in partition keys.
I'd like to be able to compare the above partition key with
Ideally the following strings开发者_开发百科 would return that partition key
Images_ Images_Jpg Jpg_ Image1.jpg
I have all the tables set up and all of the other queries, its just this one query that I can't figure out.
Thanks in advance for any help,
Matt
Table Storage does support the CompareTo method which can be used like a StartsWith. But it still might not work for you based on the types of searching you're trying to do.
MyTable.Where(t => t.PartitionKey.CompareTo("image") >= 0).ToList();
I have run into similar issues with searches against Azure tables searching on names and making sure the results were case invariant.
What I ended up doing was actually loading the data I needed from the Azure tables to an in memory collection that gets persisted in a queryable collection. I was then able to use Linq to Objects to query and get the results I wanted.
Not an elegant approach, but if the data collection is not huge and is relativley static, the size of the object in memory will be relatively benign in compassion to how much memory the VM has. Performance was also much faster.
You could also try and just have the Partition/row key and data your are trying to query in memory, run your query, iterate the partiation and row keys and return your results. Not sure if that will help resolve your question, but I throw it out as a possible approach.
Good luck!
John
I found querying Azure Table storage using LINQPad very handy. Check out Jason Halley's blog for more info and samples.
精彩评论