> ## Documentation Index
> Fetch the complete documentation index at: https://learn.nexudus.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Listing Records

> How to list and paginate through records using the Nexudus SDK.

# Listing Records

Use `SearchAsync` to retrieve paginated lists of records from any entity endpoint.

## List the first page

Retrieve the first page with the default page size (25):

```csharp theme={null}
var endpoint = new CoworkerEndpoint(client);
SearchResult<Coworker> result = await endpoint.SearchAsync();

foreach (var c in result.Records)
    Console.WriteLine($"{c.Id}: {c.FullName}");
```

## Custom page size

Specify a page number and page size:

```csharp theme={null}
SearchResult<Coworker> result = await endpoint.SearchAsync(page: 1, size: 10);

Console.WriteLine($"Page {result.CurrentPage} of {result.TotalPages}");
Console.WriteLine($"Showing {result.Records.Count} of {result.TotalItems} records");
```

## Iterate all pages

Loop through every page to process all records:

```csharp theme={null}
int page = 1;
int totalPages;

do
{
    var result = await endpoint.SearchAsync(page: page, size: 25);
    totalPages = result.TotalPages;

    foreach (var c in result.Records)
        Console.WriteLine($"{c.Id}: {c.FullName}");

    page++;
} while (page <= totalPages);
```

## SearchResult properties

The `SearchResult<T>` object returned by `SearchAsync` provides full pagination metadata:

| Property      | Type      | Description                        |
| ------------- | --------- | ---------------------------------- |
| `Records`     | `List<T>` | The records on the current page.   |
| `CurrentPage` | `int`     | The current page number (1-based). |
| `PageSize`    | `int`     | The number of records per page.    |
| `TotalItems`  | `int`     | Total number of matching records.  |
| `TotalPages`  | `int`     | Total number of pages available.   |

## Sorting results

Pass `orderBy` and `dir` parameters to control the sort order:

```csharp theme={null}
var endpoint = new BookingEndpoint(client);

// Sort by FromTime descending
var result = await endpoint.SearchAsync(orderBy: "FromTime", dir: 1);
```

| Parameter | Type     | Description                                        |
| --------- | -------- | -------------------------------------------------- |
| `orderBy` | `string` | The property name to sort by (e.g., `"FromTime"`). |
| `dir`     | `int`    | Sort direction: `0` = ascending, `1` = descending. |

If omitted, the API uses each entity's default sort order (e.g., Bookings default to `FromTime` ascending, Coworkers default to `FullName` ascending).

### Sorting with filters

Sorting can be combined with filters and pagination:

```csharp theme={null}
var filters = new Dictionary<string, string>
{
    ["Booking_Resource"] = "98765"
};

var result = await endpoint.SearchAsync(filters, page: 1, size: 50, orderBy: "FromTime", dir: 1);
```

### Sorting with typed search filters

Typed search filter classes also expose `OrderBy` and `Dir` properties:

```csharp theme={null}
var filters = new BookingSearchFilters
{
    ResourceId = 98765,
    OrderBy = "FromTime",
    Dir = 1 // descending
};

var result = await endpoint.SearchAsync(filters);
```

## Works with any entity

The same pattern applies to every endpoint in the SDK:

```csharp theme={null}
var bookings = await new BookingEndpoint(client).SearchAsync();
var products = await new ProductEndpoint(client).SearchAsync();
var businesses = await new BusinessEndpoint(client).SearchAsync();
```
