Table of Contents

Class ArithmeticOperator

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

Represents an arithmetic operator (+, -, *, /, %) used in expressions and calculations.

public class ArithmeticOperator : IElement
Inheritance
ArithmeticOperator
Implements

Examples

Simple multiplication:

// Calculate: price * quantity
Expression totalExpression = new Expression("total");
totalExpression.Add(ordersTable["price"]);
totalExpression.Add(new ArithmeticOperator(ArithmeticType.Multiply));
totalExpression.Add(ordersTable["quantity"]);

query.AddSelectItem(totalExpression);
// SQL: SELECT price * quantity AS total

Multiple operations:

// Calculate: (price * quantity) + shipping
Expression orderTotal = new Expression("order_total");
orderTotal.Add(ordersTable["price"]);
orderTotal.Add(new ArithmeticOperator(ArithmeticType.Multiply));
orderTotal.Add(ordersTable["quantity"]);
orderTotal.Add(new ArithmeticOperator(ArithmeticType.Add));
orderTotal.Add(ordersTable["shipping"]);

query.AddSelectItem(orderTotal);
// SQL: SELECT (price * quantity) + shipping AS order_total

Using with literals:

// Add 10% markup: price * 1.1
Expression markupPrice = new Expression("markup_price");
markupPrice.Add(productsTable["price"]);
markupPrice.Add(new ArithmeticOperator(ArithmeticType.Multiply));
markupPrice.Add(new Literal<decimal>(1.1m));

query.AddSelectItem(markupPrice);
// SQL: SELECT price * 1.1 AS markup_price

Modulo operation:

// Get remainder: quantity % 10
Expression remainder = new Expression("qty_remainder");
remainder.Add(ordersTable["quantity"]);
remainder.Add(new ArithmeticOperator(ArithmeticType.Modulo));
remainder.Add(new Literal<int>(10));

query.AddSelectItem(remainder);
// SQL: SELECT quantity % 10 AS qty_remainder

Division:

// Calculate average: total_price / item_count
Expression avgPrice = new Expression("avg_price");
avgPrice.Add(ordersTable["total_price"]);
avgPrice.Add(new ArithmeticOperator(ArithmeticType.Divide));
avgPrice.Add(ordersTable["item_count"]);

query.AddSelectItem(avgPrice);
// SQL: SELECT total_price / item_count AS avg_price

Remarks

ArithmeticOperator is used within Expression objects to perform mathematical calculations on column values, literals, and function results. The supported operators are:

  • Add (+)Addition
  • Subtract (-)Subtraction
  • Multiply (*)Multiplication
  • Divide (/)Division
  • Modulo (%)Remainder/modulus operation

Operators are added to expressions in the order they should be evaluated. Velocity does not automatically handle operator precedence - use parentheses (via nested expressions) if you need to control evaluation order beyond left-to-right.

Constructors

ArithmeticOperator(ArithmeticType)

Creates a new arithmetic operator.

Properties

ArithmeticType

Gets or sets the type of arithmetic operation (+, -, *, /, %).