# LINQ Queries

## Content

LINQ queries demonstrate how to operate and query the Service Now objects wrapped in an Entity Framework data model. Listed below are some examples of LINQ queries supported by the Entity framework. In the following example, it is used [Incident ](/componentone/docs/services/online-dataconnector/ado.net-provider-for-servicenow/servicenowlinq/incident)file to map the Incident datatable.

### Contains

Retrieve all entities that contain "**Server**" in the **Description** column.

```csharp
var records = context.Incident.Where(x => x.Description.Contains("Server"));
```

### Order By

Sort data by **Category** in ascending order.

```csharp
var records = (from p in context.Incident
               orderby p.Category ascending//Implementing Order By
               select p);
```

### Count

Count all entities that match a given criterion.

```csharp
var _count = (from p in context.Incident
              select p).Count();//Count Query based on number of records selected
```

### Joins

Cross-join **Incident** and **AlmAsset** tables.

```csharp
var records = from b in context.Incident
              from e in context.AlmAsset
              select new { b, e };//Defining Cross Join
```

### **Group By**

Group records from the **Incidents** table based on the **Category** property.

```csharp
 var incidentTable = context.Incident.AsEnumerable();
 var queryIncident = from b in incidentTable
                     group b by b.Category into newGroup
                     orderby newGroup.Key descending
                     select newGroup;
```