# LINQ Queries

## Content

LINQ queries demonstrate how to operate and query the Snowflake 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 CallCenter.cs file to map the CallCenter Datatable.
**Select and Filter**
Retrieve records from the **CALL\_CENTER** table where the CC\_CALL\_CENTER\_SK is "**1**.

```csharp
var records = from p in context.CallCenters
                          where p.CcCallCenterSk == 1
                          select new { p.CcCallCenterSk, p.CcName, p.CcClass };
```

**Contains**
Retrieve records from the **CALL\_CENTER** table where the **cc\_class** property contains the substring **"large".**

```csharp
var records = context.CallCenters.Where(x => x.CcClass.Contains("large")); 
```

**Limit**
Retrieve the first 10 records from the **CALL\_CENTER** table.

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

**Order by**
Retrieve all records from the **CALL\_CENTER** table and sort them in descending order based on the **cc\_class** property.

```csharp
var records = (from p in context.CallCenters
                           orderby p.CcCallCenterSk descending//Implementing Order By
                           select p);
```

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

```csharp
Query based on the number of records selected
```

**Group By**
Group records from the **CALL\_CENTER** table based on the **cc\_class** property. The groups are then ordered in descending order based on the **cc\_class**.

```csharp
var sampleTable = context.CallCenters.AsEnumerable();
var queryCreatedBy = from b in sampleTable
                     group b by b.CcClass into newGroup //Linq Group Query based on CcClass 
                     orderby newGroup.Key descending
                     select newGroup;
```