Class Query
Builds and compiles Cosmos DB SQL API queries with support for containers, filtering, grouping, ordering, and pagination. Provides parameterized query construction with input validation for containers and fields. Supports advanced features including custom SELECT projections, COUNT and EXISTS queries, and multi-container queries.
Inherited Members
Namespace: DataWeb.Data.AzureCosmosDB
Assembly: DataWeb.Data.AzureCosmosDB.dll
Syntax
public class Query
Properties
Containers
Containers (FROM / JOIN) to include in the query.
Declaration
public List<Query.Container> Containers { get; set; }
Property Value
| Type | Description |
|---|---|
| List<Query.Container> |
Count
Maximum documents to return via TOP clause. 0 = all.
Declaration
public int Count { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
Filters
WHERE filters. Use AddFilter(string, string, object, FilterMode, FilterCondition) to add entries.
Declaration
public List<Query.Filter> Filters { get; set; }
Property Value
| Type | Description |
|---|---|
| List<Query.Filter> |
GroupFields
Fields for GROUP BY clause.
Declaration
public string[] GroupFields { get; set; }
Property Value
| Type | Description |
|---|---|
| string[] |
IsPagination
Indicates whether pagination should be applied to the query results.
Declaration
public bool IsPagination { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Mode
Query mode. Currently only Select is supported.
Declaration
public QueryMode Mode { get; set; }
Property Value
| Type | Description |
|---|---|
| QueryMode |
OrderFields
Fields for ORDER BY clause.
Declaration
public string[] OrderFields { get; set; }
Property Value
| Type | Description |
|---|---|
| string[] |
PageIndex
Zero-based page index for pagination.
Declaration
public long PageIndex { get; set; }
Property Value
| Type | Description |
|---|---|
| long |
PageSize
Number of documents per page. Default is 50.
Declaration
public int PageSize { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
Parameters
Query parameters bound to filter expressions.
Declaration
public Dictionary<string, object> Parameters { get; set; }
Property Value
| Type | Description |
|---|---|
| Dictionary<string, object> |
SelectMode
Determines the SELECT projection: full rows, COUNT, or EXISTS check.
Declaration
public SelectMode SelectMode { get; set; }
Property Value
| Type | Description |
|---|---|
| SelectMode |
SelectStatement
Custom SELECT projection expression. If set, replaces the default *.
Declaration
public string SelectStatement { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
AddFilter(string, string, object, FilterMode, FilterCondition)
Adds a filter condition to the query, optionally binding a parameter value.
Declaration
public void AddFilter(string filter, string parameterName = null, object parameterValue = null, FilterMode mode = FilterMode.And, FilterCondition condition = FilterCondition.Always)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filter | The filter expression (e.g., |
| string | parameterName | Optional parameter name to bind (e.g., |
| object | parameterValue | |
| FilterMode | mode | |
| FilterCondition | condition | When NotNull, the filter is skipped if value is null/empty. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown if |
Compile()
Compiles the query into a Cosmos DB SQL API string.
Declaration
public string Compile()
Returns
| Type | Description |
|---|---|
| string |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown if no containers have been added. |
CompileSelect()
Declaration
protected string CompileSelect()
Returns
| Type | Description |
|---|---|
| string |