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

Session.ExecuteQuery(String) Method

Executes the specified SQL query and returns a result set.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v21.1.dll


public SelectedData ExecuteQuery(
    string sql


Name Type Description
sql String

Specifies an SQL statement.


Type Description

A SelectedData object, specifying the query’s result set.


Use ExecuteQuery to 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 DevExpress.Xpo.DB;
// ...
SelectedData data = GetEmployeesSimpleData();
// ...
public SelectedData GetEmployeesSimpleData() {
    const string queryString =
        @"SELECT EmployeeID, (FirstName + ' ' + LastName) as Name, City, Country 
        FROM [Northwind].[dbo].[Employees]";
    return session.ExecuteQuery(queryString);

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


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

See Also