diff --git a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs index b2c8063ae5f..c959ad0fb0b 100644 --- a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs @@ -1085,20 +1085,23 @@ private Expression Expand(Expression source, MemberIdentity member) var foreignKey = navigation.ForeignKey; if (navigation.IsCollection()) { - var innerSelectExpression = _sqlExpressionFactory.Select(targetEntityType); - var innerShapedQuery = CreateShapedQueryExpression(targetEntityType, innerSelectExpression); + var innerShapedQuery = CreateShapedQueryExpression( + targetEntityType, _sqlExpressionFactory.Select(targetEntityType)); var makeNullable = foreignKey.PrincipalKey.Properties .Concat(foreignKey.Properties) .Select(p => p.ClrType) .Any(t => t.IsNullableType()); + var innerSequenceType = innerShapedQuery.Type.TryGetSequenceType(); + var correlationPredicateParameter = Expression.Parameter(innerSequenceType); + var outerKey = entityShaperExpression.CreateKeyAccessExpression( navigation.IsDependentToPrincipal() ? foreignKey.Properties : foreignKey.PrincipalKey.Properties, makeNullable); - var innerKey = innerShapedQuery.ShaperExpression.CreateKeyAccessExpression( + var innerKey = correlationPredicateParameter.CreateKeyAccessExpression( navigation.IsDependentToPrincipal() ? foreignKey.PrincipalKey.Properties : foreignKey.Properties, @@ -1114,10 +1117,12 @@ private Expression Expand(Expression source, MemberIdentity member) Expression.Equal(outerKey, innerKey)) : Expression.Equal(outerKey, innerKey); - var correlationPredicate = _sqlTranslator.Translate(predicate); - innerSelectExpression.ApplyPredicate(correlationPredicate); + var correlationPredicate = Expression.Lambda(predicate, correlationPredicateParameter); - return innerShapedQuery; + return Expression.Call( + QueryableMethods.Where.MakeGenericMethod(innerSequenceType), + innerShapedQuery, + Expression.Quote(correlationPredicate)); } var entityProjectionExpression = (EntityProjectionExpression) diff --git a/src/EFCore/Query/EntityShaperExpression.cs b/src/EFCore/Query/EntityShaperExpression.cs index 4dbace000d7..d9e95a082a9 100644 --- a/src/EFCore/Query/EntityShaperExpression.cs +++ b/src/EFCore/Query/EntityShaperExpression.cs @@ -22,7 +22,7 @@ public EntityShaperExpression(IEntityType entityType, Expression valueBufferExpr protected override Expression VisitChildren(ExpressionVisitor visitor) { - var valueBufferExpression = (ProjectionBindingExpression)visitor.Visit(ValueBufferExpression); + var valueBufferExpression = visitor.Visit(ValueBufferExpression); return Update(valueBufferExpression); } diff --git a/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsWeakQueryInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsWeakQueryInMemoryTest.cs index f86b5a7679b..6a4c1e316c7 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsWeakQueryInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsWeakQueryInMemoryTest.cs @@ -47,5 +47,11 @@ public override Task Optional_navigation_propagates_nullability_to_manually_crea { return base.Optional_navigation_propagates_nullability_to_manually_created_left_join2(isAsync); } + + [ConditionalTheory(Skip = "issue #17620")] + public override Task Lift_projection_mapping_when_pushing_down_subquery(bool isAsync) + { + return base.Lift_projection_mapping_when_pushing_down_subquery(isAsync); + } } } diff --git a/test/EFCore.Specification.Tests/Query/ComplexNavigationsWeakQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/ComplexNavigationsWeakQueryTestBase.cs index ff076cde1bc..4cb29354172 100644 --- a/test/EFCore.Specification.Tests/Query/ComplexNavigationsWeakQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/ComplexNavigationsWeakQueryTestBase.cs @@ -178,11 +178,5 @@ public override Task Include_inside_subquery(bool isAsync) { return base.Include_inside_subquery(isAsync); } - - [ConditionalTheory(Skip = "Issue#18519")] - public override Task Lift_projection_mapping_when_pushing_down_subquery(bool isAsync) - { - return base.Lift_projection_mapping_when_pushing_down_subquery(isAsync); - } } }