- 2 minutes to read
Expressions support multiple predefined functions.
- Aggregate Functions (for example, average value).
- Date-time Functions (for example, is today).
- Logical Functions (for example, is null or empty).
- Math Functions (for example, absolute value).
- String Functions (for example, starts with).
These functions allow you to calculate values for unbound columns, implement conditional formatting or create complex filters. For example, you can only show orders that exceed the average cost and are shipped today. See Criteria Language Syntax for more information.
You can also create a custom function. For example, you can implement not starts with function.
How to Implement a Custom Function
To create a custom function, implement one of these interfaces.
- ICustomFunctionOperator - a basic custom function.
- ICustomFunctionOperatorBrowsable - a custom function accessible in expression editors.
- ICustomFunctionDisplayAttributes - a custom function accessible in expression editors, filter editors and filter menus.
- ICustomFunctionOperatorFormattable - a custom function that can be processed by an SQL database. Supports the XPO Object-Relational Mapping tool.
The How to: Implement a Custom Criteria Language Function Operator topic shows how to implement a function that extracts the month from a date-time value.
How to Register a Custom Function
A custom function should be registered in the system to make it available in expressions and/or database queries. To register a function, do one of the following:
This makes the function available in expressions and database queries created with XPO.
Pass the function to a data storage provider's RegisterCustomFunctionOperator method and add it to a dictionary's XPDictionary.CustomFunctionOperators collection.
This makes the function available in XPO queries based on dictionary entries only.
To unregister a custom function, call the CriteriaOperator.UnregisterCustomFunction method.
Refer to How to: Implement Custom Functions and Criteria in LINQ to XPO for more information on how to implement custom functions and use them in LINQ expressions created with XPO.