Table of Contents

Class BaseExpressionVisitor

Namespace
NextORM.Core
Assembly
nextorm.core.dll

Base class for the expression visitors: holds the dialect, column/alias/parameter providers, parameter list and logging state shared by the derived visitors.

public class BaseExpressionVisitor : ExpressionVisitor, ICloneable, IDisposable
Inheritance
BaseExpressionVisitor
Implements
Derived
Inherited Members
Extension Methods

Constructors

BaseExpressionVisitor(VisitorOptions)

Creates a visitor from a single VisitorOptions value.

public BaseExpressionVisitor(VisitorOptions options)

Parameters

options VisitorOptions

Fields

_builder

The SQL builder the visitor renders into, or null in parameter-only mode.

protected readonly StringBuilder? _builder

Field Value

StringBuilder

_paramMode

Whether the visitor only collects parameters and does not append SQL (parameter-only mode).

protected readonly bool _paramMode

Field Value

bool

Properties

AsPredicate

True when the built expression is used as a condition (WHERE/HAVING) instead of a value.

protected virtual bool AsPredicate { get; }

Property Value

bool

ColumnName

The name of the column currently being rendered, if any.

public string? ColumnName { get; }

Property Value

string

NeedAliasForColumn

Whether the column currently being rendered needs an alias, for example because it is cast or repeated.

public bool NeedAliasForColumn { get; }

Property Value

bool

SourceProvider

The provider that resolves the columns and table aliases of the query sources.

public IColumnsProvider SourceProvider { get; }

Property Value

IColumnsProvider

Methods

Clone()

Creates a fresh visitor with the same options but an empty builder, so a nested expression can be rendered independently and then appended to the outer SQL.

public virtual BaseExpressionVisitor Clone()

Returns

BaseExpressionVisitor

A new visitor that is not in parameter mode.

Exceptions

NotSupportedException

The current visitor is in parameter mode.

Dispose()

Returns the pooled builder and releases the visitor's resources.

public void Dispose()

Dispose(bool)

Releases the resources used by the visitor, returning the pooled builder when applicable.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true to release managed resources.

ToString()

Returns the SQL emitted into this visitor's builder.

public override string ToString()

Returns

string

The rendered SQL text.

VisitBinary(BinaryExpression)

Visits the children of the BinaryExpression.

protected override Expression VisitBinary(BinaryExpression node)

Parameters

node BinaryExpression

The expression to visit.

Returns

Expression

The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.

VisitConditional(ConditionalExpression)

Visits the children of the ConditionalExpression.

protected override Expression VisitConditional(ConditionalExpression node)

Parameters

node ConditionalExpression

The expression to visit.

Returns

Expression

The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.

VisitConstant(ConstantExpression)

Visits the ConstantExpression.

protected override Expression VisitConstant(ConstantExpression node)

Parameters

node ConstantExpression

The expression to visit.

Returns

Expression

The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.

VisitIndex(IndexExpression)

Visits the children of the IndexExpression.

protected override Expression VisitIndex(IndexExpression node)

Parameters

node IndexExpression

The expression to visit.

Returns

Expression

The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.

VisitLambda<T>(Expression<T>)

Visits the children of the Expression<TDelegate>.

protected override Expression VisitLambda<T>(Expression<T> node)

Parameters

node Expression<T>

The expression to visit.

Returns

Expression

The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.

Type Parameters

T

The type of the delegate.

Remarks

Only the body is visited. A projection lambda stored as a Expression (the single-column scalar form, for example From(scalarCte).Select(n => n + 1)) denotes its body's value; the parameter list is not a separate SQL operand, so the default ExpressionVisitor walk would visit the parameter after the body and emit the source column a second time ((n + 1)n). Higher-order array/JSON lambdas are extracted and walked by their own translators, so they do not rely on this method visiting a parameter list.

VisitMember(MemberExpression)

Visits the children of the MemberExpression.

protected override Expression VisitMember(MemberExpression node)

Parameters

node MemberExpression

The expression to visit.

Returns

Expression

The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.

VisitMethodCall(MethodCallExpression)

Visits the children of the MethodCallExpression.

protected override Expression VisitMethodCall(MethodCallExpression node)

Parameters

node MethodCallExpression

The expression to visit.

Returns

Expression

The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.

VisitNew(NewExpression)

Visits the children of the NewExpression.

protected override Expression VisitNew(NewExpression node)

Parameters

node NewExpression

The expression to visit.

Returns

Expression

The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.

VisitParameter(ParameterExpression)

Visits the ParameterExpression.

protected override Expression VisitParameter(ParameterExpression node)

Parameters

node ParameterExpression

The expression to visit.

Returns

Expression

The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.

VisitSwitch(SwitchExpression)

Visits the children of the SwitchExpression.

protected override Expression VisitSwitch(SwitchExpression node)

Parameters

node SwitchExpression

The expression to visit.

Returns

Expression

The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.

VisitTypeBinary(TypeBinaryExpression)

Visits the children of the TypeBinaryExpression.

protected override Expression VisitTypeBinary(TypeBinaryExpression node)

Parameters

node TypeBinaryExpression

The expression to visit.

Returns

Expression

The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.

Remarks

A type test has no representable SQL form: the engine has no discriminator and no runtime type switch, so the default ExpressionVisitor walk would silently render the bare operand as the condition and return wrong rows (#295). The rejection is unconditional and precedes any traversal of node.Expression, for both TypeIs and TypeEqual.

Exceptions

NotSupportedException

Always: a type-test expression cannot be translated to SQL.

VisitUnary(UnaryExpression)

Visits the children of the UnaryExpression.

protected override Expression VisitUnary(UnaryExpression node)

Parameters

node UnaryExpression

The expression to visit.

Returns

Expression

The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.