Osy#the first language built for agents
Agents firstAgentic appsWorkflowsDurable Execution — built inSecurityTestingThe editorThe UI modelOne program

Reference / Query

Skip / Take (paging)

set.OrderBy(k).Skip(n).Take(m) → OFFSET n LIMIT m

Page a query with Skip(n) (OFFSET) and Take(m) (LIMIT). The count can be a compile-time constant OR a runtime integer — a variable, parameter, or expression — so a page size chosen at runtime works directly.

stable1 example compiled by CIquerypagingauthoring

Summary#

Take(m) limits a query to the first m rows; Skip(n) skips the first n. Together they page a result set (Skip(n).Take(m)). The count for either can be a compile-time constant (Take(20)) or a runtime integer — a variable, a parameter, or any int expression (Take(pageSize)) — exactly like the parameterized LIMIT/OFFSET a database query uses. Order the query first (OrderBy) so paging is deterministic.

Signature#

set.Where(p).OrderBy(k).Skip(<int>).Take(<int>).ToList()
//                       └ OFFSET      └ LIMIT   (each count: a constant OR a runtime int)

Description#

  • Take(m) returns at most the first m rows (SQL LIMIT). Skip(n) discards the first n rows (SQL OFFSET). Skip(n).Take(m) is the page-(n/m) window.
  • The count may be runtime. Take(pageSize) / Skip(page * pageSize) accept an int variable, parameter, or expression — not just a literal. The value is read when the query runs (like a bound SQL parameter), so a page size the caller chose at runtime just works.
  • The count must be an integer. A non-integer argument is a compile error.
  • Take never throws and never over-returns. Asking for more rows than exist returns all of them; Take(0) returns none — matching C#.
  • Order first for determinism. Without an OrderBy, the database may return any rows; page a sorted query.
  • What it composes with. Where, OrderBy/ThenBy, Include, Distinct, and the single-row terminals. Skip may not precede a Select projectionTake may, and Skip may not (page first and project after, or project into a class and page the result). Neither may precede a GroupBy: only Where may.

Examples#

entity Order {
  [Required] string Name;
  decimal Total;
}

// The page and size are PARAMETERS — chosen by the caller at runtime.
Order[] PageOrders(int page, int size) {
  return Order
    .OrderByDescending(o => o.Total)
    .Skip(page * size)
    .Take(size)
    .ToList();
}

// A constant count still works exactly as before.
Order[] TopFive() {
  return Order.OrderByDescending(o => o.Total).Take(5).ToList();
}

// Take clamps: n larger than the row count returns all rows; 0 returns none.
int HowMany(int n) {
  var rows = Order.OrderBy(o => o.Name).Take(n).ToList();
  return rows.Count;
}

See also#

Related

Union / Concat / Intersect / Except

Combines two row-queries over the same entity with SQL set semantics: Union dedups, Concat keeps duplicates (UNION…

List OrderBy (in-memory)

Sort a local List<T> in memory by a key selector, returning a NEW sorted List<T> (the source is untouched). Ascending…