diff --git a/src/EFCore/Query/Internal/InvocationExpressionRemovingExpressionVisitor.cs b/src/EFCore/Query/Internal/InvocationExpressionRemovingExpressionVisitor.cs index 4cb6e906b7a..ff666bce88d 100644 --- a/src/EFCore/Query/Internal/InvocationExpressionRemovingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/InvocationExpressionRemovingExpressionVisitor.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; +using System; using System.Collections.ObjectModel; using System.Linq; using System.Linq.Expressions; @@ -14,8 +14,11 @@ protected override Expression VisitInvocation(InvocationExpression invocationExp { var invokedExpression = StripTrivialConversions(invocationExpression.Expression); + return invokedExpression is LambdaExpression lambdaExpression - ? InlineLambdaExpression(lambdaExpression, invocationExpression.Arguments) + ? AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue19511", out var isEnabled) && isEnabled + ? InlineLambdaExpression(lambdaExpression, invocationExpression.Arguments) + : Visit(InlineLambdaExpression(lambdaExpression, invocationExpression.Arguments)) : base.VisitInvocation(invocationExpression); } diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.Where.cs b/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.Where.cs index 4f0657267e8..6c80e181634 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.Where.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.Where.cs @@ -1536,6 +1536,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 isAsync) { diff --git a/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.Where.cs b/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.Where.cs index 2ccfcd44da1..958bb56b980 100644 --- a/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.Where.cs +++ b/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.Where.cs @@ -1519,6 +1519,26 @@ public virtual Task Where_expression_invoke_2(bool isAsync) entryCount: 6); } + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Where_expression_invoke_3(bool isAsync) + { + 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( + isAsync, + ss => ss.Set().Where(lambda), + entryCount: 1); + } + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_concat_string_int_comparison1(bool isAsync) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/SimpleQuerySqlServerTest.Where.cs b/test/EFCore.SqlServer.FunctionalTests/Query/SimpleQuerySqlServerTest.Where.cs index 263bc97b6c6..b94b57b2f76 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/SimpleQuerySqlServerTest.Where.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/SimpleQuerySqlServerTest.Where.cs @@ -1282,6 +1282,16 @@ FROM [Orders] AS [o] WHERE [c].[CustomerID] = N'ALFKI'"); } + public override async Task Where_expression_invoke_3(bool isAsync) + { + await base.Where_expression_invoke_3(isAsync); + + 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 isAsync) { await base.Where_concat_string_int_comparison1(isAsync);