# Read Columns

## Syntax

```
GetFields<TResult>(columns, filter, maxRows);
```

## Arguments

<table data-header-hidden><thead><tr><th width="181">Argument</th><th width="189">Data Type</th><th width="290">Description</th><th>Default Value</th></tr></thead><tbody><tr><td><em>columns</em></td><td>Expression&#x3C;Func&#x3C;T, TResult>></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></td></tr><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><p><em>orderBy</em></p><p> </p></td><td>Func&#x3C;IQueryable, IOrderedQueryable></td><td><p>Order in which the filtered records should be listed. </p><p>This parameter is optional.</p></td><td>null </td></tr><tr><td><em>includeProperties</em></td><td>string</td><td><p>Navigation properties (recognized by the key word "virtual") that should be included.</p><p>This parameter is optional.</p></td><td>""</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></tbody></table>

## Description

Gets all the columns that are specified in the parameter _columns_ from all the records of a repository that fulfill the criteria specified in the parameter _filter_.

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

If _includeProperties_ is not null, it additionally loads the navigation properties that are specified in the parameter _includeProperties_. Navigation properties are "virtual" properties of the repository, i.e. they are not real properties and are accessed by navigating to another object. They would not get loaded unless specified in this parameter.

If max&#x52;_&#x6F;ws_ is not 0, it makes sure that the number of filtered records does not exceed the specified number.

## Example

### Example 1: Reading only one specific column

The following program illustrates the function call with only one specified column:

```
var orderColumns = repo.GetFields(x => x.ProductID, 
                                  c => c.ProductID == "ADAM-567-BTO");
```

Function will load the column "ProductID" from the records of the repository that have "ADAM-567-BTO" as Production ID and store the result into the variable "orderColumns".

### Example 2: Reading multiple columns

The following program illustrates the function call with three specified columns:

```
var orderColumns = repo.GetFields(x => new { x.ProductID, 
                                             x.ID, 
                                             x.Quantity }, 
                                  c => c.ProductID == "ADAM-567-BTO");
```

Function will load the columns "ProductID", "ID" and "Quantity" from the records of the repository that have "ADAM-567-BTO" as Production ID and store the result into the variable "orderColumns".

### Example 3: Reading multiple columns with custom names

The following program illustrates the function call with three specified columns where two of them are given custom names:

```
var orderColumns = repo.GetFields(x => new { ProductName = x.ProductID, 
                                             OrderNumber = x.ID, 
                                             x.Quantity }, 
                                  c => c.ProductID == "ADAM-567-BTO");
```

Function will load the columns "ProductID", "ID" and "Quantity" from the records of the repository that have "ADAM-567-BTO" as Production ID and store the result into the variable "orderColumns", renaming the item "ProductionID" into "ProductName" and "ID" into "OrderNumber". The item "Quantity" maintains its name from the repository.

### Example 4: Reading multiple columns and multiple filter criteria

```
var orderColumns = repo.GetFields(x => new { x.ProductID, 
                                             x.ID }, 
                                  c => c.ProductID == "ADAM-567-BTO"
                                    && c.Quantity > 10 
                                    && c.IsUrgent == true);
```

Function will load the columns "ProductID" and "ID" from the records of the repository that have "ADAM-567-BTO" as Production ID, have a Quantity of more than 10 and are Urgent, and store the result into the variable "orderColumns".

### Example 5: Reading multiple columns with order + maximum limit

```
var orderColumns = repo.GetFields(x => new { x.ProductID, 
                                             x.ID }, 
                                  c => c.ProductID == "ADAM-567-BTO",
                                  o => o.OrderBy(t => t.Timestamp),  
                                  "",
                                  100);
```

Function will order the records by their Timestamp attribute, load the columns "ProductID" and "ID" from a maximum of 100 records of the ordered repository that have "ADAM-567-BTO" as Production ID and store the result into the variable "orderColumns".

### Example 6: Reading multiple columns with order + maximum limit and including a virtual property

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

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

Function will order the records by their Timestamp attribute, load the columns "ProductID" and "ID" from a maximum of 100 records of the ordered repository that have "ADAM-567-BTO" as Production ID and a Quantity of more than 10, include the virtual property "SapOrder" (a navigation property of "Production Order") and store the result into the variable "orderList".
