Class OptimizationContext
- Namespace
- LinqToDB.Internal.SqlProvider
- Assembly
- linq2db.dll
public sealed class OptimizationContext : ISqlBuilderRenderContext
- Inheritance
-
objectOptimizationContext
- 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
evaluationContextEvaluationContextdataOptionsDataOptionssqlProviderFlagsSqlProviderFlagsmappingSchemaMappingSchemaoptimizerVisitorSqlExpressionOptimizerVisitorconvertVisitorSqlExpressionConvertVisitorfactoryISqlExpressionFactoryisParameterOrderDependedboolparametersNormalizerFactoryFunc<IQueryParametersNormalizer>
Properties
ConvertVisitor
public SqlExpressionConvertVisitor ConvertVisitor { get; }
Property Value
DataOptions
public DataOptions DataOptions { get; }
Property Value
EvaluationContext
Evaluation context carrying this run's parameter values, used for render-time expression evaluation.
public EvaluationContext EvaluationContext { get; }
Property Value
Factory
public ISqlExpressionFactory Factory { get; }
Property Value
IsParameterOrderDependent
public bool IsParameterOrderDependent { get; }
Property Value
MappingSchema
public MappingSchema MappingSchema { get; }
Property Value
OptimizerVisitor
public SqlExpressionOptimizerVisitor OptimizerVisitor { get; }
Property Value
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
SqlProviderFlags
public SqlProviderFlags SqlProviderFlags { get; }
Property Value
TransformationInfoConvert
public SqlQueryVisitor.IVisitorTransformationInfo TransformationInfoConvert { get; }
Property Value
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
parameterSqlParameter
Returns
ClearParameters()
public void ClearParameters()
GetParameters()
public IReadOnlyList<SqlParameter> GetParameters()
Returns
HasParameters()
public bool HasParameters()
Returns
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
namestring
Returns
Optimize<T>(T?, NullabilityContext)
public T? Optimize<T>(T? element, NullabilityContext nullabilityContext) where T : class, IQueryElement
Parameters
elementTnullabilityContextNullabilityContext
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
elementTnullabilityContextNullabilityContext
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
dbDataTypeDbDataTypevalueobject