Skip to content

Commit

Permalink
[Query] Always pass in Members when creating NewExpression (#15536)
Browse files Browse the repository at this point in the history
They are required for binding in projection
  • Loading branch information
smitpatel authored Apr 30, 2019
1 parent afa3c25 commit 6285d61
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
24 changes: 21 additions & 3 deletions src/EFCore/Query/NavigationExpansion/NavigationExpansionHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,14 @@ public static (Expression source, ParameterExpression parameter) AddNavigationJo
var groupJoinResultTransparentIdentifierCtorInfo
= groupJoinResultType.GetTypeInfo().GetConstructors().Single();

var groupJoinResultTransparentIdentifierOuterMemberInfo = groupJoinResultType.GetTypeInfo().GetDeclaredField("Outer");
var groupJoinResultTransparentIdentifierInnerMemberInfo = groupJoinResultType.GetTypeInfo().GetDeclaredField("Inner");

var groupJoinResultSelector = Expression.Lambda(
Expression.New(groupJoinResultTransparentIdentifierCtorInfo, resultSelectorOuterParameter, resultSelectorInnerParameter),
Expression.New(
groupJoinResultTransparentIdentifierCtorInfo,
new[] { resultSelectorOuterParameter, resultSelectorInnerParameter },
new[] { groupJoinResultTransparentIdentifierOuterMemberInfo, groupJoinResultTransparentIdentifierInnerMemberInfo }),
resultSelectorOuterParameter,
resultSelectorInnerParameter);

Expand Down Expand Up @@ -180,9 +186,15 @@ var groupJoinMethodCall
var selectManyResultTransparentIdentifierCtorInfo
= selectManyResultType.GetTypeInfo().GetConstructors().Single();

var selectManyResultTransparentIdentifierOuterMemberInfo = selectManyResultType.GetTypeInfo().GetDeclaredField("Outer");
var selectManyResultTransparentIdentifierInnerMemberInfo = selectManyResultType.GetTypeInfo().GetDeclaredField("Inner");

// TODO: dont reuse parameters here?
var selectManyResultSelector = Expression.Lambda(
Expression.New(selectManyResultTransparentIdentifierCtorInfo, selectManyCollectionSelectorParameter, innerKeySelectorParameter),
Expression.New(
selectManyResultTransparentIdentifierCtorInfo,
new[] { selectManyCollectionSelectorParameter, innerKeySelectorParameter },
new[] { selectManyResultTransparentIdentifierOuterMemberInfo, selectManyResultTransparentIdentifierInnerMemberInfo }),
selectManyCollectionSelectorParameter,
innerKeySelectorParameter);

Expand Down Expand Up @@ -220,8 +232,14 @@ var selectManyMethodCall
var transparentIdentifierCtorInfo
= resultType.GetTypeInfo().GetConstructors().Single();

var transparentIdentifierOuterMemberInfo = resultType.GetTypeInfo().GetDeclaredField("Outer");
var transparentIdentifierInnerMemberInfo = resultType.GetTypeInfo().GetDeclaredField("Inner");

var resultSelector = Expression.Lambda(
Expression.New(transparentIdentifierCtorInfo, resultSelectorOuterParameter, resultSelectorInnerParameter),
Expression.New(
transparentIdentifierCtorInfo,
new[] { resultSelectorOuterParameter, resultSelectorInnerParameter },
new[] { transparentIdentifierOuterMemberInfo, transparentIdentifierInnerMemberInfo }),
resultSelectorOuterParameter,
resultSelectorInnerParameter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,14 @@ private Expression ProcessGroupJoin(MethodCallExpression methodCallExpression)
outerApplyOrderingsResult.state.CustomRootMappings.Concat(new[] { groupingMapping }).ToList(),
materializeCollectionNavigation: null);

var transparentIdentifierOuterMemberInfo = resultType.GetTypeInfo().GetDeclaredField("Outer");
var transparentIdentifierInnerMemberInfo = resultType.GetTypeInfo().GetDeclaredField("Inner");

var lambda = Expression.Lambda(
Expression.New(transparentIdentifierCtorInfo, outerApplyOrderingsResult.state.CurrentParameter, newGroupingParameter),
Expression.New(
transparentIdentifierCtorInfo,
new[] { outerApplyOrderingsResult.state.CurrentParameter, newGroupingParameter },
new[] { transparentIdentifierOuterMemberInfo, transparentIdentifierInnerMemberInfo }),
outerApplyOrderingsResult.state.CurrentParameter,
newGroupingParameter);

Expand Down Expand Up @@ -1354,8 +1360,14 @@ protected override Expression VisitConstant(ConstantExpression constantExpressio
outerState.CustomRootMappings.Concat(innerState.CustomRootMappings).ToList(),
materializeCollectionNavigation: null);

var transparentIdentifierOuterMemberInfo = resultType.GetTypeInfo().GetDeclaredField("Outer");
var transparentIdentifierInnerMemberInfo = resultType.GetTypeInfo().GetDeclaredField("Inner");

var lambda = Expression.Lambda(
Expression.New(transparentIdentifierCtorInfo, outerState.CurrentParameter, innerState.CurrentParameter),
Expression.New(
transparentIdentifierCtorInfo,
new[] { outerState.CurrentParameter, innerState.CurrentParameter },
new[] { transparentIdentifierOuterMemberInfo, transparentIdentifierInnerMemberInfo }),
outerState.CurrentParameter,
innerState.CurrentParameter);

Expand Down

0 comments on commit 6285d61

Please sign in to comment.