The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
All docs
V19.2
19.2
19.1
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

Session.ExecuteQueryAsync(String, CancellationToken) Method

Asynchronously executes the specified SQL query and returns a result set.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v19.2.dll

Declaration

public Task<SelectedData> ExecuteQueryAsync(
    string sql,
    CancellationToken cancellationToken = default(CancellationToken)
)
Public Function ExecuteQueryAsync(
    sql As String,
    cancellationToken As CancellationToken = Nothing
) As Task(Of SelectedData)
public Task<SelectedData> ExecuteQueryAsync(
    string sql,
    CancellationToken cancellationToken = default(CancellationToken)
)
Public Function ExecuteQueryAsync(
    sql As String,
    cancellationToken As CancellationToken = Nothing
) As Task(Of SelectedData)

Parameters

Name Type Description
sql String

A String value that specifies an SQL query.

cancellationToken CancellationToken

A CancellationToken object that delivers a cancellation notice to the running operation.

Parameters

Name Type Description
sql String

A String value that specifies an SQL query.

cancellationToken CancellationToken

A CancellationToken object that delivers a cancellation notice to the running operation.

Returns

Type Description
Task<SelectedData>

Data retrieved from the data store.

Returns

Type Description
Task<SelectedData>

Data retrieved from the data store.

Remarks

Use ExecuteQueryAsync to asynchronously query data stores for result sets. You can visualize result sets via the XPDataView. To learn how to access the resulting data, refer to How to: Access Data in SQL Query Results.

The example below demonstrates how to use this method. Here, session is the Session instance.

using System.Threading;
using System.Threading.Tasks;
using DevExpress.Xpo;
using DevExpress.Xpo.DB;
// ...
CancellationTokenSource cts = new CancellationTokenSource();
SelectedData data = await GetEmployeesSimpleDataAsync(cts.Token);
// ...
public async Task<SelectedData> GetEmployeesSimpleDataAsync(CancellationToken cancellationToken) {
    const string queryString = 
        @"SELECT EmployeeID, (FirstName + ' ' + LastName) as Name, City, Country 
        FROM [Northwind].[dbo].[Employees]";
    return await session.ExecuteQueryAsync(queryString, cancellationToken);
}

To learn more about executing SQL queries in XPO, refer to Direct SQL Queries.

Note

The ExecuteQueryAsync method sends queries directly, so the correct query syntax depends on a particular database server.

See Also