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

Query: Bind projection member in client eval #21458

Merged
merged 1 commit into from
Jun 29, 2020
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 @@ -127,6 +127,16 @@ public override Expression Visit(Expression expression)
return new ProjectionBindingExpression(_selectExpression, newIndex, expression.Type);
}

if (projectionBindingExpression.ProjectionMember != null)
{
// This would be SqlExpression. EntityProjectionExpression would be wrapped inside EntityShaperExpression.
var mappedProjection = (SqlExpression)_selectExpression.GetMappedProjection(
projectionBindingExpression.ProjectionMember);

return new ProjectionBindingExpression(
_selectExpression, _selectExpression.AddToProjection(mappedProjection), expression.Type);
}

throw new InvalidOperationException(CoreStrings.TranslationFailed(projectionBindingExpression.Print()));

case ParameterExpression parameterExpression:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4139,6 +4139,12 @@ public override Task Single_non_scalar_projection_after_skip_uses_join(bool asyn
return base.Single_non_scalar_projection_after_skip_uses_join(async);
}

[ConditionalTheory(Skip = "No Select after Distinct issue#17246")]
public override Task Select_distinct_Select_with_client_bindings(bool async)
{
return base.Select_distinct_Select_with_client_bindings(async);
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5980,5 +5980,17 @@ public virtual Task Single_non_scalar_projection_after_skip_uses_join(bool async
ss => ss.Set<Customer>().Select(c => c.Orders.OrderBy(o => o.OrderDate).ThenBy(o => o.OrderID).Skip(2).FirstOrDefault()),
entryCount: 86);
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Select_distinct_Select_with_client_bindings(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Order>().Where(o => o.OrderID < 10000).Select(o => o.OrderDate.Value.Year).Distinct()
.Select(e => new DTO<int> { Property = ClientMethod(e) }));
}

private static int ClientMethod(int s) => s;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5120,6 +5120,19 @@ FROM [Orders] AS [o]
) AS [t0] ON [c].[CustomerID] = [t0].[CustomerID]");
}

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

AssertSql(
@"SELECT [t].[c]
FROM (
SELECT DISTINCT DATEPART(year, [o].[OrderDate]) AS [c]
FROM [Orders] AS [o]
WHERE [o].[OrderID] < 10000
) AS [t]");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down