.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

Session.ExecuteNonQueryAsync(String, CancellationToken) Method

Asynchronously executes the specified SQL statement and returns the number of rows affected.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v21.2.dll


public Task<int> ExecuteNonQueryAsync(
    string sql,
    CancellationToken cancellationToken = default(CancellationToken)


Name Type Description
sql String

Specifies an SQL statement.

Optional Parameters

Name Type Default Description
cancellationToken CancellationToken


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


Type Description

A Task<TResult> that returns a number of affected rows.


Use ExecuteNonQueryAsync to asynchronously execute SQL statements that do not produce result sets, such as UPDATE, INSERT, and DELETE statements.

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

using System.Threading;
using DevExpress.Xpo;
// ...
CancellationTokenSource cts = new CancellationTokenSource();
await UpdateOrderDetailsAsync(cts.Token);
// ...
public async Task UpdateOrderDetailsAsync(CancellationToken cancellationToken) {
    const string queryString = 
        "UPDATE [Northwind].[dbo].[Order Details] SET [Discount] = 0.15";
    int rowsAffected = await session.ExecuteNonQueryAsync(queryString, cancellationToken);

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


The ExecuteNonQuery method sends statements directly, so the correct statement syntax depends on a particular database server.

See Also