liveBook · Manning

Pagination

As explained in .NET in Action, Second Edition

Paging divides a result set into separately retrievable portions, typically controlled by a page size and position.

Pagination lets an API return a portion of a collection instead of every result. A client can request a size with `take` and a starting offset with `skip`; web APIs may also use page numbers or cursors. section 3.1.1

Listing 3.12 Adding skip parameter to all-fonts query
app.MapGet("/",
  (int? skip, int? take) =>       #1
  AsciiArt.AllFonts.Value
    .Skip(skip ?? 0)              #2
    .Take(take ?? 100));          #3

This ASP.NET Core endpoint applies LINQ `Skip` before `Take`. Nullable query parameters default to an offset of 0 and a page size of 100. section 3.1.1

Request a page

Request `/?skip=100&take=10` to retrieve up to ten font names starting after the first hundred. Test unusual values too: values that cannot be converted to integers produce an HTTP 500 response in this implementation. section 3.1.1

How .NET in Action, Second Edition covers it

How deep it goes
Implements offset-and-size paging with defaults and discusses invalid inputs, without developing a standardized paging protocol.
Examples
Tests font-name requests with `?take=10` and `?skip=100&take=10`.
What you can do after
Apply it via ASP.NET Core and LINQ to return offset-based portions of a collection.
How it connects
Connects ASP.NET Core query parameters to LINQ Skip and Take, alongside filtering and sorting.

Also explained in

Compare how 11 books explain pagination →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET in Action, Second Edition. The section links point to the parts of the book it draws on.