# Counting Record

## Syntax

```
int Count(filter, maxRows, orderBy);
```

## Arguments

<table data-header-hidden><thead><tr><th width="136">Argument</th><th width="220">Data Type</th><th width="303">Description</th><th>Default Value</th></tr></thead><tbody><tr><td><em>filter</em></td><td>Expression&#x3C;Func&#x3C;T, bool>></td><td><p>Criteria by which the records of the repository should be filtered. </p><p>This parameter must not be empty. </p></td><td>null </td></tr><tr><td><em>maxRows</em></td><td>int?</td><td><p>Maximal number of records that should be filtered. </p><p>This parameter is optional.</p></td><td>null</td></tr><tr><td><p><em>orderBy</em></p><p> </p></td><td>Func&#x3C;IQueryable&#x3C;T>, IOrderedQueryable&#x3C;T>></td><td><p>Order in which the filtered records should be stored. </p><p>This parameter is optional.</p></td><td>null </td></tr></tbody></table>

## Description

Counts the number of all records from a repository that fulfill the criteria specified in the parameter *filter.*

If *rows* is not 0, it makes sure that the number of filtered records does not exceed the specified number, i.e. it will stop counting after the limit is reached (even if there are more records in the repository that fulfill the criteria) and the resulting number will be the maximum limit.

If *orderBy* is not null, it first orders the records according to the attributes specified in the parameter *orderBy* before counting the records from the newly ordered list.&#x20;

## Examples

### Example 1: Counting records by only one criterion

The following program illustrates the function call with only one criterion:

```
var count = repo.Count(x => x.ProductID == "ADAM-800-BTO");
```

Function will count all the records from the repository that have "ADAM-567-BTO" as Production ID and store the resulting number into the variable "count".

### Example 2: Filtering records by multiple criteria

The following program illustrates the function call with multiple criteria:

```
var count = repo.Count(x => x.ProductID == "ADAM-800-BTO"
                         && x.Quantity > 10 
                         && x.IsUrgent == true);
```

Function will count all the records from the repository that have "ADAM-567-BTO" as Production ID, have a Quantity of more than 10 and are Urgent, store the resulting number into the variable "count".

### Example 3: Filtering records by multiple criteria with maximum limit:

The following program illustrates the function call with multiple criteria and specified maximum limit:

```
var count = repo.Count(x => x.ProductID == "ADAM-800-BTO"
                         && x.Quantity > 10,
                       100);
```

Function will count a maximum of 100 records from the repository that have "ADAM-567-BTO" as Production ID and a Quantity of more than 10, and store the resulting number into the variable "countExample3". If more than 100 records fulfill the criteria, function will stop counting after the 100th record and store "100" into the variable "count".

### Example 4: Filtering records by multiple criteria with maximum limit + order:

The following program illustrates the function call with multiple criteria, specified maximum limit and order:

```
var countExample4 = repo.Get(x => x.ProductID == "ADAM-567-BTO" 
                               && c.Quantity > 10, 
                             100,
                             o => o.OrderBy(c => c.Timestamp);                            );
```

Function will order the records by their Timestamp attribute, count a maximum of 100 records from the ordered repository that have "ADAM-567-BTO" as Production ID and a Quantity of more than 10, and store the resulting number into the variable "orderList". If more than 100 records fulfill the criteria, function will stop counting after the 100th record and store "100" into the variable "count".


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://aeudoc.gitbook.io/developer/backend/data-repository/counting-record.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
