I am new to working with Azure table Storage but I have being able to put together the code below that successfully allows my query to accept filterQuery (string) specified by the user -- for ex: (Amount le 5000.00) -- and to retrieve all rows (entities) matching the criteria.
Dim sBuilder As New Syste开发者_StackOverflow社区m.Text.StringBuilder
Dim query = MyBase.CreateQuery(Of cData)("CustomerData")
Dim userQuery = String.Format("(PartitionKey eq '{0}' and {1})", AppID, filterQuery)
sBuilder.AppendFormat(userQuery)
query = query.AddQueryOption("$filter", sBuilder.ToString).AsTableServiceQuery().Take(50)
Dim results As List(Of cData) = query.Execute.ToList
I should point out that this way of allowing the user to specify the filter string is key for me since I am using a generic class that has a dictionary inside of it in order to allow my caller to pass in any number of elements to store into a given entity. Therefore, this solution allows the user to drive how he wants his query to search by and my code does not have to 'know' anything about his custom fields.
Now I need to add pagination. My understanding is that the 'Execute' method I am using handles the pagination for you so if there are 7,000 records matching the criteria, my code will sit until all the entries are retrieved/returned. However, I want to instead allow my user to specify how many entities he wants returned at a time (max results) and allow him to then make subsequent calls using continuation tokens to get the next 'batch' of matching entities.
Any thoughts on how I can achieve this without losing my ability to allow the user to specify his search criteria in a simple string?
I think you can just do query.EndExecuteSegmented(query.BeginExecuteSegmented(...))
Check out the code for SmarxToDo: http://blog.smarx.com/posts/todo-list-app-using-asp-net-mvc-and-windows-azure-tables
You may want to implement your query using REST API (http://msdn.microsoft.com/en-us/library/dd179421.aspx). You will get XML response back from storage service which you can parse to create the collection of objects.
精彩评论