Table of Contents

Class SqlParameterCastExpression

Namespace
LinqToDB.Internal.SqlQuery
Assembly
linq2db.dll

Marks one usage of a SqlParameter as needing an explicit type in the generated SQL.

public sealed class SqlParameterCastExpression : SqlExpressionBase, ISqlExpression, IQueryElement, IEquatable<ISqlExpression>
Inheritance
object
SqlParameterCastExpression
Implements
Inherited Members
Extension Methods

Remarks

The need for a cast belongs to the position, not to the parameter: one instance is shared by every usage, so a flag on it could only cast everywhere or nowhere. Wrapping the usage keeps a single parameter - a single DECLARE - and casts only where the provider requires it.

This is deliberately not a SqlCastExpression. It carries no target type of its own: the provider decides what to render (BasicSqlBuilder.GetParameterCastType), and several derive it from the value bound for the current execution - the length of the actual string, the facets of the actual decimal. Keeping it a separate node also means the code that reasons about real casts, such as the set-operation type correlation in BasicSqlOptimizer, never mistakes this marker for a cast whose type was chosen deliberately, and the cast folding in the optimizer cannot remove it.

Constructors

SqlParameterCastExpression(SqlParameter)

public SqlParameterCastExpression(SqlParameter parameter)

Parameters

parameter SqlParameter

Properties

ElementType

AST node type.

public override QueryElementType ElementType { get; }

Property Value

QueryElementType

Parameter

public SqlParameter Parameter { get; }

Property Value

SqlParameter

Precedence

public override int Precedence { get; }

Property Value

int

SystemType

public override Type SystemType { get; }

Property Value

Type

Methods

Accept(QueryElementVisitor)

Visitor support.

public override IQueryElement Accept(QueryElementVisitor visitor)

Parameters

visitor QueryElementVisitor

Returns

IQueryElement

CanBeNullable(NullabilityContext)

public override bool CanBeNullable(NullabilityContext nullability)

Parameters

nullability NullabilityContext

Returns

bool

Equals(ISqlExpression, Func<ISqlExpression, ISqlExpression, bool>)

public override bool Equals(ISqlExpression other, Func<ISqlExpression, ISqlExpression, bool> comparer)

Parameters

other ISqlExpression
comparer Func<ISqlExpression, ISqlExpression, bool>

Returns

bool

GetElementHashCode()

public override int GetElementHashCode()

Returns

int

Modify(SqlParameter)

public void Modify(SqlParameter parameter)

Parameters

parameter SqlParameter

ToString(QueryElementTextWriter)

Generates debug text representation of AST node.

public override QueryElementTextWriter ToString(QueryElementTextWriter writer)

Parameters

writer QueryElementTextWriter

Returns

QueryElementTextWriter