Skip to content

Commit 8ff5778

Browse files
committed
ExpressionProcessor supports force use of SqlCase in some cases
1 parent c9415fa commit 8ff5778

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

Orm/Xtensive.Orm/Orm/Providers/Expressions/ExpressionProcessor.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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;

Orm/Xtensive.Orm/Orm/Providers/PartialIndexFilterCompiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public string Compile(HandlerAccessor handlers, IndexInfo index)
2424
.Cast<SqlExpression>()
2525
.ToList();
2626

27-
var processor = new ExpressionProcessor(index.Filter.Expression, handlers, null, columns);
27+
var processor = new ExpressionProcessor(filter.Expression, handlers, null, true, columns);
2828
var fragment = SqlDml.Fragment(processor.Translate());
2929
var result = handlers.StorageDriver.Compile(fragment).GetCommandText();
3030
return result;

Orm/Xtensive.Orm/Orm/Providers/SqlCompiler.Helpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2009-2020 Xtensive LLC.
1+
// Copyright (C) 2009-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: Denis Krjuchkov
@@ -63,7 +63,7 @@ protected SqlProvider CreateProvider(SqlSelect statement, IEnumerable<QueryParam
6363
protected Pair<SqlExpression, IEnumerable<QueryParameterBinding>> ProcessExpression(LambdaExpression le,
6464
params IReadOnlyList<SqlExpression>[] sourceColumns)
6565
{
66-
var processor = new ExpressionProcessor(le, Handlers, this, sourceColumns);
66+
var processor = new ExpressionProcessor(le, Handlers, this, (Owner ?? RootProvider).Type == ProviderType.Sort, sourceColumns);
6767
var result = new Pair<SqlExpression, IEnumerable<QueryParameterBinding>>(
6868
processor.Translate(), processor.GetBindings());
6969
return result;

0 commit comments

Comments
 (0)