Table of Contents

Class Function

Namespace
YndigoBlue.Velocity.Model
Assembly
YndigoBlue.Velocity.dll

Represents a database function call in SELECT clauses, filters, or expressions.

public class Function : IElement, ICheckItem, IDefaultItem, IFilterItem
Inheritance
Function
Implements
Derived

Examples

Aggregate functions in SELECT:

Query query = new Query();
query.AddFromItem(ordersTable);
query.AddSelectItem(ordersTable["user_id"]);

// COUNT(order_id)
Function countFunc = new Function(FunctionType.Count, ordersTable["order_id"]);
countFunc.SetAlias("order_count");
query.AddSelectItem(countFunc);

// SUM(total)
Function sumFunc = new Function(FunctionType.Sum, ordersTable["total"]);
sumFunc.SetAlias("total_spent");
query.AddSelectItem(sumFunc);

query.AddGroupByItem(ordersTable["user_id"]);

String functions:

// UPPER(username)
Function upperFunc = new Function(FunctionType.Upper, usersTable["username"]);
query.AddSelectItem(upperFunc);

// CONCAT(first_name, ' ', last_name)
Function concatFunc = new Function(
    FunctionType.Concat,
    usersTable["first_name"],
    new Literal(" "),
    usersTable["last_name"]
);
concatFunc.SetAlias("full_name");

Date/time functions:

// NOW() or CURRENT_TIMESTAMP
Function nowFunc = new Function(FunctionType.Now);
record.SetFieldAsFunction("created_at", nowFunc);

// YEAR(order_date)
Function yearFunc = new Function(FunctionType.Year, ordersTable["order_date"]);
query.AddSelectItem(yearFunc);

Math functions:

// ROUND(price, 2)
Function roundFunc = new Function(
    FunctionType.Round,
    productsTable["price"],
    new Literal(2)
);

// ABS(balance)
Function absFunc = new Function(FunctionType.Abs, accountsTable["balance"]);

Remarks

Functions encapsulate database-specific function calls (COUNT, SUM, MAX, UPPER, NOW, etc.) in a database-agnostic way. Velocity translates function calls to the appropriate syntax for each supported database system.

Constructors

Function(FunctionType)
Function(FunctionType, IEnumerable<IElement>)
Function(FunctionType, IElement)
Function(FunctionType, params IElement[])

Properties

CheckConstraintType

Gets the type of check constraint element.

DefaultConstraintType

Gets the type of default constraint element.

Elements
FilterItemType

Gets the type of filter item.

FunctionType

Methods

IsEqual(ICheckItem)

Determines whether this check item is equal to another check item.

IsEqual(IDefaultItem)

Determines whether this default item is equal to another default item.

ToString()

Returns a string that represents the current object.