corelibraries-devexpress-dot-dataaccess-dot-sql-4a278d23.md
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
public sealed class CustomExpression :
ExpressionBase
Public NotInheritable Class CustomExpression
Inherits ExpressionBase
The following example illustrates how to create a simple CustomExpression. For general information on creating custom expressions, see Creating Criteria.
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;
}
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
Object ExpressionBase CustomExpression
See Also