Back to Devexpress

CustomExpression Class

corelibraries-devexpress-dot-dataaccess-dot-sql-4a278d23.md

latest3.6 KB
Original Source

CustomExpression Class

A custom aggregate expression that can be applied to a data column or group/sorting criteria.

Namespace : DevExpress.DataAccess.Sql

Assembly : DevExpress.DataAccess.v25.2.dll

NuGet Package : DevExpress.DataAccess

Declaration

csharp
public sealed class CustomExpression :
    ExpressionBase
vb
Public NotInheritable Class CustomExpression
    Inherits ExpressionBase

Remarks

The following example illustrates how to create a simple CustomExpression. For general information on creating custom expressions, see Creating Criteria.

csharp
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.Sql;
// ...

private SqlDataSource BindToData() {
    // Create a data source with the required connection parameters.
    Access97ConnectionParameters connectionParameters =
    new Access97ConnectionParameters("../../Data/nwind.mdb", "", "");
    SqlDataSource ds = new SqlDataSource(connectionParameters);

    // Create a query and select a table.
    SelectQuery query = new SelectQuery("MyQuery");
    Table employeesTable = new Table() { Name = "Employees" };
    query.Tables.Add(employeesTable);

    // Create a custom expression.
    CustomExpression fullName = new CustomExpression();
    fullName.Expression = "[FirstName] + ' ' + [LastName]";

    // Select a column and assign the expression to it.
    Column column = new Column();
    column.Expression = fullName;
    column.Alias = "FullName";
    query.Columns.Add(column);

    // Add the query to the collection and return the data source.
    ds.Queries.Add(query);
    return ds;
}
vb
Imports DevExpress.DataAccess.ConnectionParameters
Imports DevExpress.DataAccess.Sql
' ...

Private Function BindToData() As SqlDataSource
    ' Create a data source with the required connection parameters.
    Dim connectionParameters As New Access97ConnectionParameters("../../Data/nwind.mdb", "", "")
    Dim ds As New SqlDataSource(connectionParameters)

    ' Create a query and select a table.
    Dim query As New SelectQuery("MyQuery")
    Dim employeesTable As New Table() With { Key .Name = "Employees" }
    query.Tables.Add(employeesTable)

    ' Create a custom expression.
    Dim fullName As New CustomExpression()
    fullName.Expression = "[FirstName] + ' ' + [LastName]"

    ' Select a column and assign the expression to it.
    Dim column As New Column()
    column.Expression = fullName
    column.[Alias] = "FullName"
    query.Columns.Add(column)

    ' Add the query to the collection and return the data source.
    ds.Queries.Add(query)
    Return ds
End Function

Inheritance

Object ExpressionBase CustomExpression

See Also

CustomExpression Members

Column.Expression

Group.Expression

Sorting.Expression

DevExpress.DataAccess.Sql Namespace