From 030158c820a0b3a1d3e8593a7f7d32c1f84d29c8 Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Mon, 17 Aug 2020 14:25:22 -0700 Subject: [PATCH] InMemory: No-op for AsSplitQuery operator (#22098) Manually verified - Works for Relational - No-op for InMemory - Throws translation failure for Cosmos Resolves #22034 --- ...yableMethodTranslatingExpressionVisitor.cs | 19 +++++++++++++++++++ src/EFCore/Properties/CoreStrings.Designer.cs | 8 -------- src/EFCore/Properties/CoreStrings.resx | 3 --- ...yableMethodTranslatingExpressionVisitor.cs | 2 +- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs index e09439cd014..2096eb16933 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs @@ -71,6 +71,25 @@ protected InMemoryQueryableMethodTranslatingExpressionVisitor( protected override QueryableMethodTranslatingExpressionVisitor CreateSubqueryVisitor() => new InMemoryQueryableMethodTranslatingExpressionVisitor(this); + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression) + { + if (methodCallExpression.Method.IsGenericMethod + && methodCallExpression.Arguments.Count == 1 + && methodCallExpression.Arguments[0].Type.TryGetSequenceType() != null + && string.Equals(methodCallExpression.Method.Name, "AsSplitQuery", StringComparison.Ordinal)) + { + return Visit(methodCallExpression.Arguments[0]); + } + + return base.VisitMethodCall(methodCallExpression); + } + /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in diff --git a/src/EFCore/Properties/CoreStrings.Designer.cs b/src/EFCore/Properties/CoreStrings.Designer.cs index 232603a907c..46e75e9b842 100644 --- a/src/EFCore/Properties/CoreStrings.Designer.cs +++ b/src/EFCore/Properties/CoreStrings.Designer.cs @@ -2468,14 +2468,6 @@ public static string IncludeWithCycle([CanBeNull] object navigationName, [CanBeN GetString("IncludeWithCycle", nameof(navigationName), nameof(inverseNavigationName)), navigationName, inverseNavigationName); - /// - /// Unhandled method '{methodName}'. - /// - public static string UnhandledMethod([CanBeNull] object methodName) - => string.Format( - GetString("UnhandledMethod", nameof(methodName)), - methodName); - /// /// Runtime parameter extraction lambda must have one QueryContext parameter. /// diff --git a/src/EFCore/Properties/CoreStrings.resx b/src/EFCore/Properties/CoreStrings.resx index 21ae743bc56..93740200239 100644 --- a/src/EFCore/Properties/CoreStrings.resx +++ b/src/EFCore/Properties/CoreStrings.resx @@ -1322,9 +1322,6 @@ The Include path '{navigationName}->{inverseNavigationName}' results in a cycle. Cycles are not allowed in no-tracking queries. Either use a tracking query or remove the cycle. - - Unhandled method '{methodName}'. - Runtime parameter extraction lambda must have one QueryContext parameter. diff --git a/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitor.cs index b80e7fd4731..4a1a8721ab8 100644 --- a/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitor.cs @@ -493,7 +493,7 @@ LambdaExpression GetLambdaExpressionFromArgument(int argumentIndex) => return _subquery ? (Expression)null - : throw new NotImplementedException(CoreStrings.UnhandledMethod(method.Name)); + : throw new InvalidOperationException(CoreStrings.TranslationFailed(methodCallExpression.Print())); } private sealed class EntityShaperNullableMarkingExpressionVisitor : ExpressionVisitor