Table of Contents

Interface IDataQuery

Namespace
CMS.DataEngine
Assembly
CMS.DataEngine.dll

Data query interface

public interface IDataQuery : IDataQuerySettings, IWhereCondition, IQueryParameters, IQueryObjectWithValue, IQueryObject
Inherited Members
Extension Methods

Properties

AllowMaterialization

If true, the query allows materialization

bool AllowMaterialization { get; set; }

Property Value

bool

ClassName

Class name

string ClassName { get; set; }

Property Value

string

ConnectionStringName

Query connection string name

string ConnectionStringName { get; set; }

Property Value

string

Count

Number of actual records retrieved from the database

int Count { get; }

Property Value

int

CustomQueryText

Custom query text

string CustomQueryText { get; set; }

Property Value

string

DataSource

Data source that provides the query data. If not set, the query queries the database directly

DataQuerySource DataSource { get; set; }

Property Value

DataQuerySource

DefaultOrderByColumns

Default order by columns used in case if needed, and order by is not specified

string DefaultOrderByColumns { get; set; }

Property Value

string

HasDataSource

Returns true if the query has specific data source

bool HasDataSource { get; }

Property Value

bool

IncludeBinaryData

If true, the query includes the object binary data

bool IncludeBinaryData { get; set; }

Property Value

bool

IsCombinedQuery

If true, this query is combined from several queries. When additional parameters are applied to it, it will be wrapped into a nested query.

bool IsCombinedQuery { get; set; }

Property Value

bool

QueryName

Query name

string QueryName { get; set; }

Property Value

string

QueryText

Query text

string QueryText { get; }

Property Value

string

Result

System.Data.DataSet with the result.

DataSet Result { get; }

Property Value

DataSet
See Also

ReturnsSingleColumn

Returns true if the query returns single column

bool ReturnsSingleColumn { get; set; }

Property Value

bool

SupportsReader

Gets a value indicating whether the query supports the ExecuteReader(CommandBehavior, bool) method. Otherwise the Execute() method must be used.

bool SupportsReader { get; }

Property Value

bool

Tables

Collection of the result tables

DataTableCollection Tables { get; }

Property Value

DataTableCollection

TotalRecords

Gets the number of total records when paging is used. Gets updated once the query executes

int TotalRecords { get; }

Property Value

int

Methods

ApplySettings(AbstractQueryObject)

Applies the given settings to the query

IDataQuery ApplySettings(AbstractQueryObject parameters)

Parameters

parameters AbstractQueryObject

Parameters to apply

Returns

IDataQuery

ApplySettings(Action<DataQuerySettings>)

Applies the given settings to the query

IDataQuery ApplySettings(Action<DataQuerySettings> parameters)

Parameters

parameters Action<DataQuerySettings>

Parameters to apply

Returns

IDataQuery

AsIDQuery()

Creates an ID query from the given query

IDataQuery AsIDQuery()

Returns

IDataQuery

AsMaterializedList(string, bool)

Makes a materialized list from the given query

IDataQuery AsMaterializedList(string columnName = null, bool distinct = false)

Parameters

columnName string

Column name to output

distinct bool

If true, only distinct IDs are selected

Returns

IDataQuery

AsNested<TResult>(NestedQuerySettings)

Creates a nested query from the given query

TResult AsNested<TResult>(NestedQuerySettings settings = null) where TResult : IDataQuery<TResult>, new()

Parameters

settings NestedQuerySettings

Settings

Returns

TResult

Type Parameters

TResult

AsSingleColumn(string, bool)

Creates a single column query from the given query

IDataQuery AsSingleColumn(string defaultColumn = null, bool forceColumn = false)

Parameters

defaultColumn string

Specific column to use in case query doesn't return single column yet

forceColumn bool

If true, the given column is forced to the output

Returns

IDataQuery

AsSubQuery()

Modifies the query to be able to be used as a sub-query, e.g. for usage in WHERE A IN ([query]). Ensures single column result, and removes order by from the result.

IDataQuery AsSubQuery()

Returns

IDataQuery

As<T>()

Changes the type of the query to another type

T As<T>() where T : IDataQuery, new()

Returns

T

Type Parameters

T

Execute()

Executes the current query and returns it's results as a System.Data.DataSet.

DataSet Execute()

Returns

DataSet

ExecuteNonQuery()

Executes the current query and returns the number of rows affected.

int ExecuteNonQuery()

Returns

int

ExecuteNonQueryAsync(CancellationToken?)

Asynchronously executes the current query and returns a task returning the number of rows affected.

Task<int> ExecuteNonQueryAsync(CancellationToken? cancellationToken = null)

Parameters

cancellationToken CancellationToken?

The cancellation instruction.

Returns

Task<int>

ExecuteReader(CommandBehavior, bool)

Executes the current query and returns it's results as an System.Data.IDataReader. The SupportsReader flag indicates whether this operation is supported.

IDataReader ExecuteReader(CommandBehavior commandBehavior = CommandBehavior.Default, bool newConnection = false)

Parameters

commandBehavior CommandBehavior

Command behavior for the reader.

newConnection bool

If true, the reader will be executed using its own dedicated connection

Returns

IDataReader

Returns the data reader resulting from query execution, or null.

Exceptions

NotSupportedException

Thrown when the query does not support reader.

ExecuteReaderAsync(CommandBehavior, bool, CancellationToken?)

Asynchronously executes the current query and returns it's results as an System.Data.IDataReader. The SupportsReader flag indicates whether this operation is supported.

Task<IDataReader> ExecuteReaderAsync(CommandBehavior commandBehavior = CommandBehavior.Default, bool newConnection = false, CancellationToken? cancellationToken = null)

Parameters

commandBehavior CommandBehavior

Command behavior for the reader.

newConnection bool

If true, the reader will be executed using its own dedicated connection

cancellationToken CancellationToken?

The cancellation instruction.

Returns

Task<IDataReader>

Returns a task returning either the data reader resulting from query execution, or null.

Exceptions

NotSupportedException

Thrown when the query does not support reader.

ExecuteScalar()

Executes the current query and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.

object ExecuteScalar()

Returns

object

ExecuteScalarAsync(CancellationToken?)

Asynchronously executes the current query and returns a task returning the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.

Task<object> ExecuteScalarAsync(CancellationToken? cancellationToken = null)

Parameters

cancellationToken CancellationToken?

The cancellation instruction.

Returns

Task<object>

ForEachRow(Action<DataRow>, int)

Executes the given action for each item (DataRow) in the result. Processes the items in batches of the given size.

void ForEachRow(Action<DataRow> rowAction, int batchSize = -1)

Parameters

rowAction Action<DataRow>

Row action

batchSize int

Batch size. 0 means no batch processing. By default uses current paging settings.

GetAsyncEnumerableResult(CommandBehavior, bool, CancellationToken)

Exposes an enumerator for asynchronous iteration over data records representing the result of this query.

IAsyncEnumerable<IDataRecord> GetAsyncEnumerableResult(CommandBehavior commandBehavior = CommandBehavior.Default, bool newConnection = false, CancellationToken cancellationToken = default)

Parameters

commandBehavior CommandBehavior

Command behavior for the underlying reader.

newConnection bool

If true, the underlying reader will be executed using its own dedicated connection.

cancellationToken CancellationToken

The cancellation instruction.

Returns

IAsyncEnumerable<IDataRecord>

Exposes an enumerator that provides asynchronous iteration over an System.Data.IDataRecord instances.

Remarks

The returned data records can contain additional system columns (TOTAL_RECORDS) when a paged query is being executed. The columns support the framework infrastructure and should not be relied on in custom code.

Exceptions

NotSupportedException

Thrown when the query does not support reader.

GetCompleteQueryParameters(DataQuerySettings)

Returns query parameter container filled with the complete settings of current query.

QueryParameters GetCompleteQueryParameters(DataQuerySettings settings = null)

Parameters

settings DataQuerySettings

Parameters for the query

Returns

QueryParameters

Remarks

Wraps distinct paged query as nested so the row number column required for paging doesn't thwart the distinct selection.

GetCompleteSettings(IDataQuery)

Gets the complete parameters for the query execution

DataQuerySettings GetCompleteSettings(IDataQuery executingQuery = null)

Parameters

executingQuery IDataQuery

Executing query for which the parameters are retrieved

Returns

DataQuerySettings

GetEnumerableResult(CommandBehavior, bool)

Gets an enumeration of data records representing the result of this query.

IEnumerable<IDataRecord> GetEnumerableResult(CommandBehavior commandBehavior = CommandBehavior.Default, bool newConnection = false)

Parameters

commandBehavior CommandBehavior

Command behavior for the underlying reader.

newConnection bool

If true, the underlying reader will be executed using its own dedicated connection.

Returns

IEnumerable<IDataRecord>

Returns the enumeration resulting from query execution.

Exceptions

NotSupportedException

Thrown when the query does not support reader.

GetExecutingQuery(DataQuerySettings)

Gets the query to execute against database

IDataQuery GetExecutingQuery(DataQuerySettings settings = null)

Parameters

settings DataQuerySettings

Parameters for the query

Returns

IDataQuery

GetFullQueryText(bool, bool, DataQuerySettings)

Gets the full query text including resolved parameters

string GetFullQueryText(bool expand = false, bool includeParameters = true, DataQuerySettings settings = null)

Parameters

expand bool

If true, the parameters are expanded

includeParameters bool

If true, parameter declarations are included if parameters are not expanded

settings DataQuerySettings

Query settings

Returns

string

GetListResult<T>()

Gets the result as a list of values from the first column that the query returns. Excludes null values from the result.

IList<T> GetListResult<T>()

Returns

IList<T>

Type Parameters

T

GetScalarResultAsync<T>(T, CancellationToken?)

Asynchronously returns a task returning a value from the first column of the first row in the result set returned by the query cast to given type. Additional columns or rows are ignored.

Task<T> GetScalarResultAsync<T>(T defaultValue = default, CancellationToken? cancellationToken = null)

Parameters

defaultValue T

Default value if result not found or not capable to convert to output type

cancellationToken CancellationToken?

The cancellation instruction.

Returns

Task<T>

Type Parameters

T

GetScalarResult<T>(T)

Returns a value from the first column of the first row in the result set returned by the query cast to given type. Additional columns or rows are ignored.

T GetScalarResult<T>(T defaultValue = default)

Parameters

defaultValue T

Default value if result not found or not capable to convert to output type.

Returns

T

Type Parameters

T

GetSource()

Gets a source for this query

QuerySource GetSource()

Returns

QuerySource

HasCompatibleSource(IDataQuery)

Returns true if the given query is an external source

bool HasCompatibleSource(IDataQuery query)

Parameters

query IDataQuery

Nested query

Returns

bool

Select<T>(Func<DataRow, T>)

Transforms the current result

IEnumerable<T> Select<T>(Func<DataRow, T> func)

Parameters

func Func<DataRow, T>

Select function

Returns

IEnumerable<T>

Type Parameters

T