问题
My question is exactly this one. However, the Azure Storage API has changed and all answers I can find for this question deal with the old version. How do handle queries that return more than 1000 items in the current API version? The query fetching less than 1000 items looks like this:
var query = new TableQuery<TermScoreEntity>()
.Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, Name));
var table = _tableClient.GetTableReference("scores");
foreach (var termScoreEntity in table.ExecuteQuery(query))
result.Add(termScoreEntity.RowKey, termScoreEntity.Score);
回答1:
Have you tried to retrieve more than 1000 entities with your above code? I think use simple ExecuteQuery
is enough.
The documentation only said it has 1,000 limitation for pure REST requests, the ExecuteQuery
API internally use this rest api, but automatically cut to multiple requests, each of them has a limitation of 1,000.
So if you use the .NET package, you don't need to worry about this limitation, the library already handle this for you. You can refer to this thread for more information.
Here is some key code for ExecuteQuery
from Azure SDK, you would find actually the max number is 9223372036854775807L
if you don't specify the take
number:
internal IEnumerable<DynamicTableEntity> Execute(CloudTableClient client, CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext)
{
CommonUtility.AssertNotNullOrEmpty("tableName", table.Name);
TableRequestOptions modifiedOptions = TableRequestOptions.ApplyDefaults(requestOptions, client);
operationContext = operationContext ?? new OperationContext();
return CommonUtility.LazyEnumerable<DynamicTableEntity>((Func<IContinuationToken, ResultSegment<DynamicTableEntity>>) (continuationToken =>
{
TableQuerySegment<DynamicTableEntity> local_0 = this.ExecuteQuerySegmented((TableContinuationToken) continuationToken, client, table, modifiedOptions, operationContext);
return new ResultSegment<DynamicTableEntity>(local_0.Results)
{
ContinuationToken = (IContinuationToken) local_0.ContinuationToken
};
}), this.takeCount.HasValue ? (long) this.takeCount.Value : long.MaxValue);
}
回答2:
Your code looks correct, and basically looks the same as http://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-tables/#retrieve-all-entities - "How to: Retrieve all entities in a partition"
Are you sure there are more than 1000 entities in that partition? You can check this a couple different ways:
- Use Visual Studio or some other storage explorer to run the same query and see how many results you get.
- Use Fiddler while running your code and see if there are continuation tokens being returned in the response. If there are continuation tokens then the code you are using should automatically follow them and create a new request. If there are no continuation tokens then that means there are no more entities matching your query.
来源:https://stackoverflow.com/questions/26960437/return-more-than-1000-entities-of-a-windows-azure-table-query