1- // Copyright (C) 2008-2021 Xtensive LLC.
1+ // Copyright (C) 2008-2024 Xtensive LLC.
22// This code is distributed under MIT license terms.
33// See the License.txt file in the project root for more information.
44// Created by: Alexey Kochetov
@@ -42,6 +42,7 @@ private readonly Dictionary<QueryParameterIdentity, QueryParameterBinding> bindi
4242 private readonly List < QueryParameterBinding > otherBindings = new List < QueryParameterBinding > ( ) ;
4343
4444 private readonly bool fixBooleanExpressions ;
45+ private readonly bool preferCaseOverVariant ;
4546 private readonly bool emptyStringIsNull ;
4647 private readonly bool dateTimeEmulation ;
4748 private readonly bool dateTimeOffsetEmulation ;
@@ -332,9 +333,9 @@ protected override SqlExpression VisitConditional(ConditionalExpression expressi
332333 var boolCheck = fixBooleanExpressions
333334 ? booleanExpressionConverter . BooleanToInt ( check )
334335 : check ;
335- // var varCheck = boolCheck as SqlVariant;
336- // if (!varCheck.IsNullReference())
337- // return SqlDml.Variant(varCheck.Id, ifFalse, ifTrue);
336+ var varCheck = boolCheck as SqlVariant ;
337+ if ( ! preferCaseOverVariant && ! varCheck . IsNullReference ( ) )
338+ return SqlDml . Variant ( varCheck . Id , ifFalse , ifTrue ) ;
338339 var @case = SqlDml . Case ( ) ;
339340 if ( fixBooleanExpressions && IsBooleanExpression ( expression ) ) {
340341 @case [ check ] = booleanExpressionConverter . BooleanToInt ( ifTrue ) ;
@@ -464,7 +465,7 @@ private SqlExpression TryUnwrapEnum(SqlContainer container)
464465 // Constructors
465466
466467 public ExpressionProcessor (
467- LambdaExpression lambda , HandlerAccessor handlers , SqlCompiler compiler , params IReadOnlyList < SqlExpression > [ ] sourceColumns )
468+ LambdaExpression lambda , HandlerAccessor handlers , SqlCompiler compiler , bool preferCaseOverVariant , params IReadOnlyList < SqlExpression > [ ] sourceColumns )
468469 {
469470 ArgumentValidator . EnsureArgumentNotNull ( lambda , "lambda" ) ;
470471 ArgumentValidator . EnsureArgumentNotNull ( handlers , "handlers" ) ;
@@ -473,6 +474,7 @@ public ExpressionProcessor(
473474 this . compiler = compiler ; // This might be null, check before use!
474475 this . lambda = lambda ;
475476 this . sourceColumns = sourceColumns ;
477+ this . preferCaseOverVariant = preferCaseOverVariant ;
476478
477479 providerInfo = handlers . ProviderInfo ;
478480 driver = handlers . StorageDriver ;
0 commit comments