---
title: "Query"
description: "Query"
url: "https://www.contentstack.com/docs/developers/sdks/content-delivery-sdk/dot-net/reference/query"
product: "Contentstack"
doc_type: "guide"
audience:
  - developers
  - admins
version: "current"
last_updated: "2026-09-22"
---

# Query

## Query

A class that defines a query that is used to query for Entry instance.

When Personalize creates a variant in the CMS, it assigns a "Variant Alias" to identify that specific variant. When fetching entry variants using the Delivery API, you can pass variant aliases in place of variant UIDs in thex-cs-variant-uidheader.

## AddQuery

Add a custom query against specified key.

```
using Contentstack.Core;
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().AddQuery("key", "value").Find<Entry>();
```

field uid.

field value

## IncludeCount

Retrieve count and data of objects in result.

```
using Contentstack.Core;
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().IncludeCount().Find<Entry>();
```

## IncludeBranch

Include branch for publish content.

```
using Contentstack.Core;
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().IncludeBranch().Find<Entry>();
```

## IncludeFallback

Include fallback locale publish content, if specified locale content is not publish.

```
using Contentstack.Core;
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> entry = await stack.ContentType("content_Type_uid").Query().IncludeFallback().Find<Entry>();
```

## IncludeMetadata

The includeMetadata method will add the meta information to the response.

```
using Contentstack.Core;
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> entry = await stack.ContentType("content_Type_uid").Query().IncludeMetadata().Find<Entry>();
```

## includeEmbeddedItems

Include Embedded Objects (Entries and Assets) along with entry/entries details.

```
using Contentstack.Core;
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> entry = await stack.ContentType("content_Type_uid").Query().includeEmbeddedItems().Find<Entry>();
```

## IncludeOnlyReference

Specifies an array of except keys that would be excluded in the response.

```
using Contentstack.Core;
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> entry = await stack.ContentType("content_Type_uid").Query().IncludeOnlyReference(new String[]{"name", "description"},"referenceUid").Find<Entry>();
```

Array of the only reference keys to be included in response.

Key who has reference to some other class object.

## IncludeExceptReference

Specifies an array of except keys that would be excluded in the response.

```
using Contentstack.Core;
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> entry = await stack.ContentType("content_Type_uid").Query().IncludeExceptReference(new String[]{"name", "description"},"referenceUid").Find<Entry>();
```

Array of the except reference keys to be excluded in response.

Key who has reference to some other class object.

## IncludeReference

Add a constraint that requires a particular reference key details.

```
using Contentstack.Core;
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> entry = await stack.ContentType("content_Type_uid").Query().IncludeReference("reference_uid_1").Find<Entry>();
```

Key that to be constrained.

## IncludeReferenceContentTypeUID

This method also includes the content type UIDs of the referenced entries returned in the response.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().IncludeReferenceContentTypeUID().Find<Entry>();
```

## IncludeReference

Add a constraint that requires a particular reference key details.

```
using Contentstack.Core;
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().IncludeReference(new String[]{"reference_uid_1", "reference_uid_2"}).Find<Entry>();
```

Array key that to be constrained.

## ReferenceIn

Retrieve entries based reference in query

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentType contentTypeObj = stack.ContentType("contentType_id");

Query query = contentTypeObj.Query();
query.Where("email_address","content@email.com");

ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().ReferenceIn("user", query).Find<Entry>();
```

They key to constraint on

Query object

## ReferenceNotIn

Retrieve entries based reference not in query

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentType contentTypeObj = stack.ContentType("contentType_id");

Query query = contentTypeObj.Query();
query.Where("email_address","content@email.com");

ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().ReferenceNotIn("user", query).Find<Entry>();
```

The key to constraint on

Query object

## Regex

Add a regular expression constraint for finding string values that match the provided regular expression.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> entry = await stack.ContentType("content_type_uid").Query().Regex("name", "^browser").Find<Entry>();
using Contentstack.Core;
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> entry = await stack.ContentType("content_type_uid").Query().Regex("name", "^browser", "i").Find<Entry>();
```

The key to be constrained.

The regular expression pattern to match.

Any of the following supported Regular expression modifiers.

*   use _i_ for case-insensitive matching.
*   use _m_ for making dot match newlines.
*   use _x_ for ignoring whitespace in regex

## RemoveQuery

Remove provided query key from custom query if exist.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_type_uid").Query().RemoveQuery("query_key").Find<Entry>();
```

Query name to remove.

## SetCachePolicy

To set cache policy using Query instance.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_type_uid").Query().SetCachePolicy(CachePolicy.NetworkElseCache).Find<Entry>();
```

CachePolicy instance

## SetLocale

Sets the locale.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_type_uid").Query().SetLocale("en-us").Find<Entry>();
```

Locale to fetch entry

## SetHeader

To set headers for Contentstack rest calls.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_type_uid").Query().SetHeader("custom_key", "custom_value").Find<Entry>();
```

header name.

header value against given header name.

## RemoveHeader

Remove header key.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> entry = await stack.ContentType("content_type_uid").Query().RemoveHeader("header_to_remove").Find<Entry>();
```

key to be remove from header

## WhereTags

Include tags with which to search entries.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().WhereTags(new String[] {"tag_1", tag_2}).Find<Entry>();
```

Array of tags you want to match in the entries

## Skip

The number of objects to skip before returning any.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Skip(20).Find<Entry>();
```

No of objects to skip.

## Limit

A limit on the number of objects to return.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Limit(20).Find<Entry>();
```

No of objects to limit.

## Ascending

Sort the results in ascending order with the given key.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Ascending("name").Find<Entry>();
```

The key to order by.

## Descending

Sort the results in descending order with the given key.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Descending("name").Find<Entry>();
```

The key to order by.

## And

Combines all the queries together using AND operator

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentType contentTypeObj = stack.ContentType("contentType_id");

Query query1 = contentTypeObj.Query();
query1.Where("username","content");

Query query2 = contentTypeObj.Query();
query2.Where("email_address","content@email.com");

List<Query> queryList = new List<Query>();
queryList.Add(query1);
queryList.Add(query2);

ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().And(queryList).Find<Entry>();
```

List of Query instances on which AND query executes.

## Or

Add a constraint to fetch all entries which satisfy any queries.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentType contentTypeObj = stack.ContentType("contentType_id");

Query query1 = contentTypeObj.Query();
query1.Where("username","content");

Query query2 = contentTypeObj.Query();
query2.Where("email_address","content@email.com");

List<Query> queryList = new List<Query>();
queryList.Add(query1);
queryList.Add(query2);

ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Or(queryList).Find<Entry>();
```

List of Query instances on which OR query executes.

## Except

Specifies list of field uids that would be excluded from the response.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Except(new String[] {"name", description }).Find<Entry>();
```

field uid which get excluded from the response.

## Only

Specifies an array of 'only' keys in BASE object that would be 'included' in the response.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Only(new String[] {"name", description }).Find<Entry>();
```

Array of the 'only' keys to be included in response.

## Exists

Add a constraint that requires, a specified key exists in response.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Exist("title").Find<Entry>();
```

The key to be constrained.

## NotExists

Add a constraint that requires, a specified key does not exists in response.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().NotExist("title").Find<Entry>();
```

The key to be constrained.

## NotEqualTo

Add a constraint to the query that requires a particular key's entry to be not equal to the provided value.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().NotEqualTo("title", "Demo").Find<Entry>();
```

the key to be constrained.

The object that must not be equaled.

## Where

Add a constraint to the query that requires a particular key entry's value not be contained in the provided array.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Where("title", "Demo").Find<Entry>();
```

the key to be constrained.

Field value which get included from the response.

## NotContainedIn

Add a constraint to the query that requires a particular key entry's value not be contained in the provided array.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().NotContainedIn("title", new Object[]{ "Demo", "Welcome"}).Find<Entry>();
```

the key to be constrained.

The list of values the key object should not be.

## ContainedIn

Add a constraint to the query that requires a particular key's entry to be contained in the provided array.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().ContainedIn("title", new Object[]{ "Demo", "Welcome"}).Find<Entry>();
```

the key to be constrained.

The possible values for the key's object.

## LessThanOrEqualTo

Add a constraint to the query that requires a particular key entry to be less than or equal to the provided value.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().LessThanOrEqualTo("age", 20).Find<Entry>();
```

the key to be constrained.

The value that provides an upper bound or equal.

## LessThan

Add a constraint to the query that requires a particular key entry to be less than the provided value.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().LessThan("age", 20).Find<Entry>();
```

the key to be constrained.

The value that provides an upper bound.

## GreaterThanOrEqualTo

Add a constraint to the query that requires a particular key entry to be greater than or equal to the provided value.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().GreaterThanOrEqualTo("age", 20).Find<Entry>();
```

the key to be constrained.

The value that provides a lower bound or equal.

## GreaterThan

Add a constraint to the query that requires a particular key entry to be greater than the provided value.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().GreaterThan("age", 20).Find<Entry>();
```

the key to be constrained.

The value that provides an lower bound.

## Find

Execute a Query and Caches its result (Optional)

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Find<Entry>();
```

## FindOne

Execute a Query and Caches its result (Optional)

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().FindOne<Entry>();
```

## Count

Retrieve only count of entries in result.

```
using Contentstack.Core; 
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Count();
```

## Variants

The variants method retrieves details of a specific entry variant or an array of entry variants based on the applied query.

When Personalize creates a variant in the CMS, it assigns a "Variant Alias" to identify that specific variant. When fetching entry variants using the Delivery API, you can pass variant aliases in place of variant UIDs in the x-cs-variant-uid header.

```
Example:
using Contentstack.Core;
using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");

ContentstackCollection<Entry> collection = await stack
						.ContentType("content_Type_uid")
						.Query()
						.Variant(new String[]{"variant_uid1/variant_alias1", "variant_uid2/variant_alias2"})
						.Find<Entry>();
```

List of variants

## Query

## Query | .NET Delivery SDK | Contentstack

Query defines and runs queries for Entry instances in the .NET Delivery SDK, supporting filters and variant aliases for fetching content.