Skip to content

Query: Throw error for translating Lambda right away #23483

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
1 commit merged into from
Dec 2, 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 @@ -325,7 +325,7 @@ protected override Expression VisitInvocation(InvocationExpression invocationExp
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override Expression VisitLambda<T>(Expression<T> lambdaExpression)
=> null;
=> throw new InvalidOperationException(CoreStrings.TranslationFailed(lambdaExpression.Print()));

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ protected override Expression VisitInvocation(InvocationExpression invocationExp
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override Expression VisitLambda<T>(Expression<T> lambdaExpression)
=> QueryCompilationContext.NotTranslatedExpression;
=> throw new InvalidOperationException(CoreStrings.TranslationFailed(lambdaExpression.Print()));

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ protected override Expression VisitInvocation(InvocationExpression invocationExp

/// <inheritdoc />
protected override Expression VisitLambda<T>(Expression<T> lambdaExpression)
=> QueryCompilationContext.NotTranslatedExpression;
=> throw new InvalidOperationException(CoreStrings.TranslationFailed(lambdaExpression.Print()));

/// <inheritdoc />
protected override Expression VisitListInit(ListInitExpression listInitExpression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2001,26 +2001,52 @@ public virtual Task Projection_take_predicate_projection(bool async)
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Ternary_in_client_eval_assigns_correct_types(bool async)
{ return AssertQuery(
async,
ss => ss.Set<Order>()
{
return AssertQuery(
async,
ss => ss.Set<Order>()

.Where(o => o.OrderID < 10300)
.OrderBy(e => e.OrderID)
.Select(
o => new
{
CustomerID = ClientMethod(o.CustomerID),
OrderDate = o.OrderDate.HasValue ? o.OrderDate.Value : new DateTime(o.OrderID - 10000, 1, 1),
OrderDate2 = o.OrderDate.HasValue == false ? new DateTime(o.OrderID - 10000, 1, 1) : o.OrderDate.Value
}),
assertOrder: true,
elementAsserter: (e, a) =>
{
AssertEqual(e.CustomerID, a.CustomerID);
AssertEqual(e.OrderDate, a.OrderDate);
AssertEqual(e.OrderDate2, a.OrderDate2);
});
.Where(o => o.OrderID < 10300)
.OrderBy(e => e.OrderID)
.Select(
o => new
{
CustomerID = ClientMethod(o.CustomerID),
OrderDate = o.OrderDate.HasValue ? o.OrderDate.Value : new DateTime(o.OrderID - 10000, 1, 1),
OrderDate2 = o.OrderDate.HasValue == false ? new DateTime(o.OrderID - 10000, 1, 1) : o.OrderDate.Value
}),
assertOrder: true,
elementAsserter: (e, a) =>
{
AssertEqual(e.CustomerID, a.CustomerID);
AssertEqual(e.OrderDate, a.OrderDate);
AssertEqual(e.OrderDate2, a.OrderDate2);
});
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task VisitLambda_should_not_be_visited_trivially(bool async)
{
return AssertTranslationFailed(() => AssertQuery(
async,
ss =>
{
var orders = ss.Set<Order>().Where(o => o.CustomerID.StartsWith("A")).ToList();

return ss.Set<Customer>()
.Select(c => new
{
Customer = c,
HasOrder = orders.Any(o => o.CustomerID == c.CustomerID)
});
},
elementSorter: e => e.Customer.CustomerID,
elementAsserter: (e, a) =>
{
AssertEqual(e.Customer, a.Customer);
AssertEqual(e.HasOrder, a.HasOrder);
}));
}

private static string ClientMethod(string s) => s;
Expand Down