# LINQ Queries

## Content

LINQ queries demonstrate how to operate and query the Kintone objects wrapped in an Entity Framework data model. Listed below are some examples of LINQ queries supported by the Entity framework.


**Select and Filter**
Retrieve records from the **Accounts** table where the **AccountID** is "**155**".

```csharp
var records = from p in context.Accounts
              where p.AccountId == "155"
              select p;
```


**Contains**
Retrieve records from the **Accounts** table that contains the letter "**A**" in the **Name** column.
```csharp 
var records = from p in context.Accounts
              where p.Name.Contains("A") //using Contains to display names that have A in their name
              select p;
```


**Limit** 
Retrieve the first 10 records from the **Accounts** table. This helps to limit the display of records. 
```csharp 
var records = (from p in context.Accounts                select p).Take(10); //taking 10 records. 
``` 


**Order by**
Retrieve the first 10 records from the **Accounts** table and sort them in **descending** order based on the **Age** property.

```csharp 
var records = (from p in context.Accounts
               orderby p.Age descending//Implementing Order By
               select p).Take(10); //taking 10 records
``` 


**Count** 
Count all records that match a given criterion. 
```csharp 
var _count = (from p in context.Accounts
              select p).Count();//Count Query based on the number of records selected
```


**Group By** 
Group records from the **Accounts** table based on the **Address** property.  
```csharp 
var accountsTable = context.Accounts.AsEnumerable();
var queryAccounts = from b in accountsTable
                    group b by b.Address into newGroup
                    orderby newGroup.Key descending
                    select newGroup;
```


**Joins** 
Cross-join between **Accounts** and **Products** tables. 
```csharp 
var records = from b in context.Accounts
              from e in context.Products
              select new { b, e };//Defining Cross Join
```