Fork me on GitHub

Paging Edit on GitHub

For paged access to data in Marten, just use the Take() and Skip() Linq operators. To get the total number of documents matching a query without having to execute the query twice, use the new Stats() Linq operator to also capture the total as shown in this sample:

Missing code sample 'using-query-statistics' -- Wait for dotnet stdocs to catch up reading samples or CTRL+SHIFT+R to force refresh

For the sake of completeness, the SQL generated in the operation above by Marten would be:

select,, count(1) OVER() as total_rows from public.mt_doc_target as d where CAST( ->> 'Number' as integer) > :arg0 LIMIT 5

The Stats() Linq operator can be used in conjunction with Include() and within batch queries. Marten does not yet support using Stats() within the compiled query.