[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Collapse]eXpress Persistent Objects
 [Expand]Product Information
 [Expand]Getting Started
 [Collapse]Feature Center
  [Expand]Data Representation
  [Expand]Object Relational Mapping
  [Expand]Connecting to a Data Store
  [Expand]Data Exchange and Manipulation
  [Collapse]Querying a Data Store
    Creating Criteria
    Direct SQL Queries
    Free Joins
    Limitations of CriteriaOperator.Parse
    LINQ to XPO
    LINQPad Context Driver
    Stored Procedures
  [Expand]Using XPO in Web Applications
 [Expand]Design-Time Features
 [Expand]Member Tables
 [Expand]API Reference
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Direct SQL Queries

In XPO, you can execute direct SQL queries against a database and obtain query results as scalar values, result sets or object collections.

Expanded Executing SQL Statements

To execute a SQL statement that does not produce a result set, call the Session.ExecuteNonQuery method as shown below.

To execute a SQL query and obtain a scalar value, call the Session.ExecuteScalar method.

To execute a SQL query and obtain a result set, call the Session.ExecuteQuery method.

Expanded Visualizing Query Results

To visualize query results, you can:

To accomplish this, you need to provide a non-persistent class whose members specify a result set's column structure. This class will be used to map result set columns to XPDataView columns or object properties.

In the following code example, the EmployeeSimple class corresponds to a result set returned via the GetEmployeesSimpleData function shown above. This class is used to populate an XPDataView with columns, and to obtain a collection of objects from a result set.

If you do not want to show all class members in an XPDataView or if their order differs from the result set, then you can provide additional mapping information to obtain the proper columns in the correct order, as shown below.

Expanded See Also

Is this topic helpful?​​​​​​​