# LINQ Queries

## Content

LINQ queries demonstrate how to operate and query the OData objects wrapped in an Entity Framework data model. Below are some examples of LINQ queries supported by the Entity framework.
**Contains**
Retrieve all records from the **Books** table that contain "A" in their **Author** name.

```csharp
var records = from p in context.Books
              where p.Author.Contains("A")
              select p;
```

**Count**
Count all entities that match a given criterion.

```csharp
var _count = (from p in context.Books
              select p).Count();
```

**Filter**
Select records from the table **Books** that belong to **Location\_City** equal to **Delhi**.

```csharp
var records = from p in context.Books
              where p.Location_City == "Delhi"
              select p;
```

**Group By**
Group records from the **Books** table based on the **Location\_City** property. The groups are then ordered in descending order based on the **Location\_City**.

```csharp
var booksTable = context.Books.AsEnumerable();
 var queryBooks = from b in booksTable
                  group b by b.Location_City into newGroup
                  orderby newGroup.Key descending
                  select newGroup;
```

**Join**
Cross join between **Books** and **Employees** tables.

```csharp
var records = from b in context.Books
              from e in context.Employees
              select new { b, e };
```

**Limit**
Retrieve the first 10 records from the **Books** table.

```csharp
var records = (from p in context.Books
                   select p).Take(10);
```

**Order By**
Sort records from the **Books** table by **Title** in descending order.

```csharp
var records = from p in context.Books
                      orderby p.Title descending
                      select p;
```


