From 8d88a82c6a2943863df6c4661656ebfe0aa40a98 Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Tue, 7 Jan 2020 12:23:04 -0800 Subject: [PATCH] Query: Unwind nested invocation expressions Resolves #19511 Issue: When we unwound the first level, we did not visit it recursively. --- ...tionExpressionRemovingExpressionVisitor.cs | 2 +- .../Query/NorthwindWhereQueryCosmosTest.cs | 10 ++++++++++ .../Query/NorthwindWhereQueryTestBase.cs | 20 +++++++++++++++++++ .../Query/NorthwindWhereQuerySqlServerTest.cs | 10 ++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/EFCore/Query/Internal/InvocationExpressionRemovingExpressionVisitor.cs b/src/EFCore/Query/Internal/InvocationExpressionRemovingExpressionVisitor.cs index 7e32bd41d0d..c6c6ee9d381 100644 --- a/src/EFCore/Query/Internal/InvocationExpressionRemovingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/InvocationExpressionRemovingExpressionVisitor.cs @@ -17,7 +17,7 @@ protected override Expression VisitInvocation(InvocationExpression invocationExp var invokedExpression = StripTrivialConversions(invocationExpression.Expression); return invokedExpression is LambdaExpression lambdaExpression - ? InlineLambdaExpression(lambdaExpression, invocationExpression.Arguments) + ? Visit(InlineLambdaExpression(lambdaExpression, invocationExpression.Arguments)) : base.VisitInvocation(invocationExpression); } diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindWhereQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindWhereQueryCosmosTest.cs index 0e9197e998c..5a897c4a891 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindWhereQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindWhereQueryCosmosTest.cs @@ -1561,6 +1561,16 @@ FROM root c WHERE ((c[""Discriminator""] = ""Customer"") AND (c[""CustomerID""] = ""ALFKI""))"); } + public override async Task Where_expression_invoke_3(bool async) + { + await base.Where_expression_invoke_3(async); + + AssertSql( + @"SELECT c +FROM root c +WHERE ((c[""Discriminator""] = ""Customer"") AND (c[""CustomerID""] = ""ALFKI""))"); + } + [ConditionalTheory(Skip = "Issue #17246")] public override async Task Where_concat_string_int_comparison1(bool async) { diff --git a/test/EFCore.Specification.Tests/Query/NorthwindWhereQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindWhereQueryTestBase.cs index 5d45ad362ba..e26a2cfefdf 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindWhereQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindWhereQueryTestBase.cs @@ -1527,6 +1527,26 @@ public virtual Task Where_expression_invoke_2(bool async) entryCount: 6); } + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Where_expression_invoke_3(bool async) + { + Expression> lambda3 = c => c.CustomerID == "ALFKI"; + var customerParameter2 = Expression.Parameter(typeof(Customer)); + var lambda2 = Expression.Lambda>( + Expression.Invoke(lambda3, customerParameter2), + customerParameter2); + + var customerParameter = Expression.Parameter(typeof(Customer)); + var lambda = Expression.Lambda>( + Expression.Invoke(lambda2, customerParameter), + customerParameter); + return AssertQuery( + async, + ss => ss.Set().Where(lambda), + entryCount: 1); + } + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_concat_string_int_comparison1(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs index 431b8c44d90..509933bf69c 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs @@ -1287,6 +1287,16 @@ FROM [Orders] AS [o] WHERE [c].[CustomerID] = N'ALFKI'"); } + public override async Task Where_expression_invoke_3(bool async) + { + await base.Where_expression_invoke_3(async); + + AssertSql( + @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] = N'ALFKI'"); + } + public override async Task Where_concat_string_int_comparison1(bool async) { await base.Where_concat_string_int_comparison1(async);