Skip to content

Commit

Permalink
Query: Translate correlation predicate on Owned collection during sub…
Browse files Browse the repository at this point in the history
…query translation

Resolves #18519
  • Loading branch information
smitpatel committed Oct 23, 2019
1 parent 5a0b029 commit 21db42a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Query/EntityShaperExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit 21db42a

Please sign in to comment.