'Azure.Data.Tables querying only next record (limit/take 1?)

I am using the quite new NuGet package Azure.Data.Tables-package with .NET 6 with two Azure Functions. One function is writing some records to a table. The other function is timer triggered and should pick up only one record at a time. The next record is identified by a DateTime column called Next.

So I have some code like this:

var yesterday = DateTime.UtcNow.Add(TimeSpan.FromDays(-1));
Pageable<MyEntity> queriedEntities = TableClient.Query<MyEntity>(filter: TableClient.CreateQueryFilter($"Next gt {yesterday}"));

Now I don't want the Azure function to pull all records to the memory while I only want to work with one record. In MySQL for example I would do it with LIMIT 1. ORDER BY is not required. It should only be one record for each run.

How do I add this limitation to the code sample above? Is it even possible? I read about take option, but I don't get it...



Solution 1:[1]

To get just one item you can query like this

var entity = await tableClient.QueryAsync<T>(filter: TableClient.CreateQueryFilter($"Next gt {yesterday}"), maxPerPage: 1).FirstOrDefaultAsync();

Note: I'm using the System.Linq.Async package here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Thomas