Class FnBlock
A function call in a query, such as "toupper(CompanyName)" or "year(OrderDate)".
public class FnBlock : BaseBlock
- Inheritance
-
FnBlock
- Inherited Members
Remarks
The functions a query may call are fixed, registered by the static constructor below and listed by name together with their return and argument types. They follow the OData set: the string functions, the date parts, and rounding.
Constructors
FnBlock(string, List<BaseBlock>)
Create a call to a registered function.
public FnBlock(string fnName, List<BaseBlock> exprs)
Parameters
Properties
DataType
The data type the function returns.
public override DataType? DataType { get; }
Property Value
Expressions
The arguments passed to the function, in order.
public IEnumerable<BaseBlock> Expressions { get; }
Property Value
FnName
The name of the function being called, e.g. "toupper".
public string FnName { get; }
Property Value
Methods
CreateFrom(string, Type)
Parse a function call written as text.
public static FnBlock CreateFrom(string source, Type entityType)
Parameters
sourcestringThe call, e.g. "toupper(CompanyName)".
entityTypeTypeThe entity type any property arguments are resolved against.
Returns
- FnBlock
The parsed call.
GetArgTypes(string)
The argument types a registered function takes, in order.
public static List<DataType> GetArgTypes(string fnName)
Parameters
fnNamestringThe function name.
Returns
Exceptions
- KeyNotFoundException
No function is registered under that name.
GetReturnType(string)
The type a registered function returns.
public static DataType? GetReturnType(string fnName)
Parameters
fnNamestringThe function name.
Returns
- DataType
The return type.
Exceptions
- KeyNotFoundException
No function is registered under that name.
RegisterFn(string, params DataType[])
Register a function that queries may call. Names are matched case-insensitively.
public static void RegisterFn(string name, params DataType[] dataTypes)
Parameters
namestringThe function name as clients will write it.
dataTypesDataType[]The return type first, then one type per argument.
ToExpression(Expression)
Build the call as a LINQ expression, mapping the function name onto the matching CLR method or property.
public override Expression ToExpression(Expression inExpr)
Parameters
inExprExpressionThe query's lambda parameter.
Returns
- Expression
The expression that computes the function's result.
Exceptions
- Exception
The function is registered but has no expression mapping here.