Class BaseExpressionVisitor
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
optionsVisitorOptions
Fields
_builder
The SQL builder the visitor renders into, or null in parameter-only mode.
protected readonly StringBuilder? _builder
Field Value
_paramMode
Whether the visitor only collects parameters and does not append SQL (parameter-only mode).
protected readonly bool _paramMode
Field Value
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
ColumnName
The name of the column currently being rendered, if any.
public string? ColumnName { get; }
Property Value
NeedAliasForColumn
Whether the column currently being rendered needs an alias, for example because it is cast or repeated.
public bool NeedAliasForColumn { get; }
Property Value
SourceProvider
The provider that resolves the columns and table aliases of the query sources.
public IColumnsProvider SourceProvider { get; }
Property Value
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
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
nodeBinaryExpressionThe 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
nodeConditionalExpressionThe 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
nodeConstantExpressionThe 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
nodeIndexExpressionThe 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
nodeExpression<T>The expression to visit.
Returns
- Expression
The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.
Type Parameters
TThe 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
nodeMemberExpressionThe 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
nodeMethodCallExpressionThe 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
nodeNewExpressionThe 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
nodeParameterExpressionThe 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
nodeSwitchExpressionThe 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
nodeTypeBinaryExpressionThe 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
nodeUnaryExpressionThe expression to visit.
Returns
- Expression
The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.