Skip to content

Commit

Permalink
Fix to #27356 - Collection_navigation_equal_to_null_for_subquery fail…
Browse files Browse the repository at this point in the history
…s after merging from release/6.0

Improvement on the previous patch fix (#26744). We were not taking into the account scenario where collection projected from FirstOrDefault was compared to null. Collection can only be null if the parent entity is null, so we can safely apply the same optimization we do for anonymous types and required entities.

Fixes #27356
  • Loading branch information
maumar committed Feb 11, 2022
1 parent 9d51382 commit ae6f74d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
{
var projection = translatedSubquery.ShaperExpression;
if (projection is NewExpression
|| RemoveConvert(projection) is EntityShaperExpression { IsNullable: false })
|| RemoveConvert(projection) is EntityShaperExpression { IsNullable: false }
|| RemoveConvert(projection) is CollectionResultExpression)
{
var anySubquery = Expression.Call(
QueryableMethods.AnyWithoutPredicate.MakeGenericMethod(translatedSubquery.Type.GetSequenceType()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5546,7 +5546,7 @@ protected static bool ClientEvalPredicate(Order order)
protected internal uint ClientEvalSelector(Order order)
=> order.EmployeeID % 10 ?? 0;

[ConditionalTheory(Skip = "Issue#20445")]
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Collection_navigation_equal_to_null_for_subquery(bool async)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4589,11 +4589,10 @@ public override async Task Collection_navigation_equal_to_null_for_subquery(bool
AssertSql(
@"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region]
FROM [Customers] AS [c]
WHERE (
SELECT TOP(1) [o].[OrderID]
WHERE NOT (EXISTS (
SELECT 1
FROM [Orders] AS [o]
WHERE [c].[CustomerID] = [o].[CustomerID]
ORDER BY [o].[OrderID]) IS NULL");
WHERE [c].[CustomerID] = [o].[CustomerID]))");
}

public override async Task Dependent_to_principal_navigation_equal_to_null_for_subquery(bool async)
Expand Down

0 comments on commit ae6f74d

Please sign in to comment.