Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conditional expression handling entity equality visitor #16351

Merged
merged 1 commit into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected override Expression VisitTypeBinary(TypeBinaryExpression typeBinaryExp
{
// This is for "x is y"
var visitedExpression = Visit(typeBinaryExpression.Expression);
var visitedTypeBinary= typeBinaryExpression.Update(Unwrap(visitedExpression));
var visitedTypeBinary = typeBinaryExpression.Update(Unwrap(visitedExpression));
return visitedExpression is EntityReferenceExpression entityWrapper
? entityWrapper.Update(visitedTypeBinary)
: (Expression)visitedTypeBinary;
Expand All @@ -106,7 +106,7 @@ protected override Expression VisitConditional(ConditionalExpression conditional
var newIfTrue = Visit(conditionalExpression.IfTrue);
var newIfFalse = Visit(conditionalExpression.IfFalse);

var newConditional = conditionalExpression.Update(newTest, Unwrap(newIfTrue), Unwrap(newIfFalse));
var newConditional = conditionalExpression.Update(Unwrap(newTest), Unwrap(newIfTrue), Unwrap(newIfFalse));

// TODO: the true and false sides may refer different entity types which happen to have the same
// CLR type (e.g. shared entities)
Expand Down
11 changes: 11 additions & 0 deletions test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.Where.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2016,5 +2016,16 @@ public virtual Task Decimal_cast_to_double_works(bool isAsync)
ps => ps.Where(p => (double?)p.UnitPrice > 100),
entryCount: 2);
}

[ConditionalTheory] // issue #16335
[MemberData(nameof(IsAsyncData))]
public virtual Task Where_is_conditional(bool isAsync)
{
var customer = new Customer();

return AssertQuery<Product>(
isAsync,
ps => ps.Where(p => p is Product ? false : true));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1772,5 +1772,18 @@ public override async Task TypeBinary_short_circuit(bool isAsync)
FROM [Orders] AS [o]
WHERE @__p_0 = CAST(1 AS bit)");
}

public override async Task Where_is_conditional(bool isAsync)
{
await base.Where_is_conditional(isAsync);

AssertSql(
@"SELECT [p].[ProductID], [p].[Discontinued], [p].[ProductName], [p].[SupplierID], [p].[UnitPrice], [p].[UnitsInStock]
FROM [Products] AS [p]
WHERE CASE
WHEN CAST(1 AS bit) = CAST(1 AS bit) THEN CAST(0 AS bit)
ELSE CAST(1 AS bit)
END = CAST(1 AS bit)");
}
}
}