Table of Contents

Class OptimizationContext

Namespace
LinqToDB.Internal.SqlProvider
Assembly
linq2db.dll
public sealed class OptimizationContext : ISqlBuilderRenderContext
Inheritance
object
OptimizationContext
Implements
Extension Methods

Constructors

OptimizationContext(EvaluationContext, DataOptions, SqlProviderFlags, MappingSchema, SqlExpressionOptimizerVisitor, SqlExpressionConvertVisitor, ISqlExpressionFactory, bool, Func<IQueryParametersNormalizer>)

public OptimizationContext(EvaluationContext evaluationContext, DataOptions dataOptions, SqlProviderFlags sqlProviderFlags, MappingSchema mappingSchema, SqlExpressionOptimizerVisitor optimizerVisitor, SqlExpressionConvertVisitor convertVisitor, ISqlExpressionFactory factory, bool isParameterOrderDepended, Func<IQueryParametersNormalizer> parametersNormalizerFactory)

Parameters

evaluationContext EvaluationContext
dataOptions DataOptions
sqlProviderFlags SqlProviderFlags
mappingSchema MappingSchema
optimizerVisitor SqlExpressionOptimizerVisitor
convertVisitor SqlExpressionConvertVisitor
factory ISqlExpressionFactory
isParameterOrderDepended bool
parametersNormalizerFactory Func<IQueryParametersNormalizer>

Properties

ConvertVisitor

public SqlExpressionConvertVisitor ConvertVisitor { get; }

Property Value

SqlExpressionConvertVisitor

DataOptions

public DataOptions DataOptions { get; }

Property Value

DataOptions

EvaluationContext

Evaluation context carrying this run's parameter values, used for render-time expression evaluation.

public EvaluationContext EvaluationContext { get; }

Property Value

EvaluationContext

Factory

public ISqlExpressionFactory Factory { get; }

Property Value

ISqlExpressionFactory

IsParameterOrderDependent

public bool IsParameterOrderDependent { get; }

Property Value

bool

MappingSchema

public MappingSchema MappingSchema { get; }

Property Value

MappingSchema

OptimizerVisitor

public SqlExpressionOptimizerVisitor OptimizerVisitor { get; }

Property Value

SqlExpressionOptimizerVisitor

ShareParametersByAccessor

When set (combined multi-statement command render), a later statement reuses an earlier statement's parameter when they share a value accessor (AccessorId), so the merged command references one @p (matching the remote separate-command path) instead of minting @p_1. Cross-statement only: enable on the render context and call PromoteParametersForSharing() between statements.

public bool ShareParametersByAccessor { get; set; }

Property Value

bool

SqlProviderFlags

public SqlProviderFlags SqlProviderFlags { get; }

Property Value

SqlProviderFlags

TransformationInfoConvert

public SqlQueryVisitor.IVisitorTransformationInfo TransformationInfoConvert { get; }

Property Value

SqlQueryVisitor.IVisitorTransformationInfo

Methods

AddParameter(SqlParameter)

Registers parameter with the command's parameter set and returns the parameter to render (possibly a deduplicated/renamed instance).

public SqlParameter AddParameter(SqlParameter parameter)

Parameters

parameter SqlParameter

Returns

SqlParameter

ClearParameters()

public void ClearParameters()

GetParameters()

public IReadOnlyList<SqlParameter> GetParameters()

Returns

IReadOnlyList<SqlParameter>

HasParameters()

public bool HasParameters()

Returns

bool

NormalizeParameterName(string?)

Normalizes name through the query parameters name normalizer, registers it as used, and returns the resulting collision-free name.

public string? NormalizeParameterName(string? name)

Parameters

name string

Returns

string

Optimize<T>(T?, NullabilityContext)

public T? Optimize<T>(T? element, NullabilityContext nullabilityContext) where T : class, IQueryElement

Parameters

element T
nullabilityContext NullabilityContext

Returns

T

Type Parameters

T

OptimizeAndConvertAll<T>(T, NullabilityContext)

The whole render-time pipeline, in one traversal. SqlExpressionConvertVisitor derives from SqlExpressionOptimizerVisitor, so a single Convert(OptimizationContext, NullabilityContext, IQueryElement) pass optimizes, lowers, and runs the CompareNulls null-guard reduce on each node as it passes over it — collapsing the old five passes (optimize, convert, reduce, simplify, convert) to one. Optimization over the un-lowered AST (the rules that only match abstract nodes) already happens during query build in SelectQueryOptimizerVisitor, so re-running it here was redundant.

public T OptimizeAndConvertAll<T>(T element, NullabilityContext nullabilityContext) where T : class, IQueryElement

Parameters

element T
nullabilityContext NullabilityContext

Returns

T

Type Parameters

T

PromoteParametersForSharing()

Promotes the parameters emitted so far (through the just-rendered statement) into the cross-statement sharing map, so a later statement in the same combined command that references the same value accessor reuses them. No-op unless ShareParametersByAccessor is set. Call between statements of a combined command.

public void PromoteParametersForSharing()

SuggestDynamicParameter(DbDataType, object?)

public SqlParameter SuggestDynamicParameter(DbDataType dbDataType, object? value)

Parameters

dbDataType DbDataType
value object

Returns

SqlParameter