I'm updating my project to use Azure.Data.Tables
12.6.1, and I can't figure out where to specify a Take
value to limit the number of entities returned from a query.
In other words, I want to do something like this:
var limit = 150;
var results = table.QueryAsync<T>(limit);
await foreach (var page in results.AsPages().ConfigureAwait(false)) {
// Regardless of how the server pages the results,
// only the top [limit] items are returned.
}
In the old API, you could set a Take
property on the query object. How do I do this in the new API?
As @Skin points out, the current SDK does not expose an explicit API for Take
, but that was an intentional decision to ensure that it is clearer to developers what is really happening from the service perspective.
The old SDK supported a full IQueryable
API, which made it easy to create very expensive queries that performed filtering client side after fetching the whole table from the service.
Although Take
doesn't have the same problems as other Linq methods, the service doesn't really support it. It can only limit the number of results for a paged result (which is capped at 1000 by the service).
While I agree it is not as simple as a Take API, the current API makes it fairly straightforward to implement the equivalent functionality, while not hiding the fact that you may actually fetch more than your Take limit from the service.
This sample demonstrates how to iterate through the pages with a max items per page set.