From c655d115f4738a8081f522507357831589af4718 Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Thu, 22 Aug 2019 17:26:02 -0700 Subject: [PATCH] Query: Throw better exception message for client eval Resolves #17387 --- ...yableMethodTranslatingExpressionVisitor.cs | 94 +++---- ...yExpressionTranslatingExpressionVisitor.cs | 2 +- ...yableMethodTranslatingExpressionVisitor.cs | 115 +++++++-- ...yableMethodTranslatingExpressionVisitor.cs | 234 ++++++++++-------- ...yableMethodTranslatingExpressionVisitor.cs | 10 + .../Query/QueryNoClientEvalTestBase.cs | 72 +++--- .../Query/UdfDbFunctionTestBase.cs | 147 +++++------ .../Query/FiltersTestBase.cs | 15 +- .../Query/GearsOfWarQueryTestBase.cs | 18 +- .../Query/IncludeAsyncTestBase.cs | 4 +- .../Query/IncludeTestBase.cs | 4 +- .../Query/QueryNavigationsTestBase.cs | 18 +- .../SimpleQueryTestBase.ResultOperators.cs | 16 +- .../Query/SimpleQueryTestBase.Select.cs | 2 +- .../Query/SimpleQueryTestBase.Where.cs | 14 +- .../Query/SimpleQueryTestBase.cs | 36 +-- .../BuiltInDataTypesSqliteTest.cs | 5 +- .../Query/GearsOfWarQuerySqliteTest.cs | 68 ++--- 18 files changed, 493 insertions(+), 381 deletions(-) diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs index b877e3f1875..7f0eba862d3 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs @@ -115,10 +115,7 @@ protected override ShapedQueryExpression CreateShapedQueryExpression(Type elemen /// 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 ShapedQueryExpression TranslateAll(ShapedQueryExpression source, LambdaExpression predicate) - { - throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print())); - } + protected override ShapedQueryExpression TranslateAll(ShapedQueryExpression source, LambdaExpression predicate) => null; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -126,10 +123,7 @@ protected override ShapedQueryExpression TranslateAll(ShapedQueryExpression sour /// 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 ShapedQueryExpression TranslateAny(ShapedQueryExpression source, LambdaExpression predicate) - { - throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print())); - } + protected override ShapedQueryExpression TranslateAny(ShapedQueryExpression source, LambdaExpression predicate) => null; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -144,7 +138,7 @@ protected override ShapedQueryExpression TranslateAverage(ShapedQueryExpression || selectExpression.Limit != null || selectExpression.Offset != null) { - throw new InvalidOperationException(CoreStrings.TranslationFailed(selector.Print())); + return null; } if (selector != null) @@ -185,8 +179,7 @@ protected override ShapedQueryExpression TranslateCast(ShapedQueryExpression sou /// protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression source1, ShapedQueryExpression source2) { - throw new InvalidOperationException(CoreStrings.TranslationFailed( - source1.Print() + "; " + source2.Print())); + return null; } /// @@ -197,7 +190,7 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s /// protected override ShapedQueryExpression TranslateContains(ShapedQueryExpression source, Expression item) { - throw new InvalidOperationException(CoreStrings.TranslationFailed(item.Print())); + return null; } /// @@ -213,12 +206,16 @@ protected override ShapedQueryExpression TranslateCount(ShapedQueryExpression so || selectExpression.Limit != null || selectExpression.Offset != null) { - throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print())); + return null; } if (predicate != null) { source = TranslateWhere(source, predicate); + if (source == null) + { + return null; + } } var translation = _sqlExpressionFactory.ApplyDefaultTypeMapping( @@ -244,7 +241,7 @@ protected override ShapedQueryExpression TranslateCount(ShapedQueryExpression so /// protected override ShapedQueryExpression TranslateDefaultIfEmpty(ShapedQueryExpression source, Expression defaultValue) { - throw new InvalidOperationException(CoreStrings.TranslationFailed(defaultValue.Print())); + return null; } /// @@ -268,7 +265,7 @@ protected override ShapedQueryExpression TranslateDistinct(ShapedQueryExpression /// protected override ShapedQueryExpression TranslateElementAtOrDefault(ShapedQueryExpression source, Expression index, bool returnDefault) { - throw new InvalidOperationException(CoreStrings.TranslationFailed(index.Print())); + return null; } /// @@ -279,8 +276,7 @@ protected override ShapedQueryExpression TranslateElementAtOrDefault(ShapedQuery /// protected override ShapedQueryExpression TranslateExcept(ShapedQueryExpression source1, ShapedQueryExpression source2) { - throw new InvalidOperationException(CoreStrings.TranslationFailed( - source1.Print() + "; " + source2.Print())); + return null; } /// @@ -294,6 +290,10 @@ protected override ShapedQueryExpression TranslateFirstOrDefault(ShapedQueryExpr if (predicate != null) { source = TranslateWhere(source, predicate); + if (source == null) + { + return null; + } } var selectExpression = (SelectExpression)source.QueryExpression; @@ -315,8 +315,7 @@ protected override ShapedQueryExpression TranslateFirstOrDefault(ShapedQueryExpr /// protected override ShapedQueryExpression TranslateGroupBy(ShapedQueryExpression source, LambdaExpression keySelector, LambdaExpression elementSelector, LambdaExpression resultSelector) { - throw new InvalidOperationException(CoreStrings.TranslationFailed( - keySelector.Print() + "; " + elementSelector.Print() + "; " + resultSelector.Print())); + return null; } /// @@ -338,8 +337,7 @@ protected override ShapedQueryExpression TranslateGroupJoin(ShapedQueryExpressio /// protected override ShapedQueryExpression TranslateIntersect(ShapedQueryExpression source1, ShapedQueryExpression source2) { - throw new InvalidOperationException(CoreStrings.TranslationFailed( - source1.Print() + "; " + source2.Print())); + return null; } /// @@ -350,8 +348,7 @@ protected override ShapedQueryExpression TranslateIntersect(ShapedQueryExpressio /// protected override ShapedQueryExpression TranslateJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector) { - throw new InvalidOperationException(CoreStrings.TranslationFailed( - outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + resultSelector.Print())); + return null; } /// @@ -365,6 +362,10 @@ protected override ShapedQueryExpression TranslateLastOrDefault(ShapedQueryExpre if (predicate != null) { source = TranslateWhere(source, predicate); + if (source == null) + { + return null; + } } var selectExpression = (SelectExpression)source.QueryExpression; @@ -387,8 +388,7 @@ protected override ShapedQueryExpression TranslateLastOrDefault(ShapedQueryExpre /// protected override ShapedQueryExpression TranslateLeftJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector) { - throw new InvalidOperationException(CoreStrings.TranslationFailed( - outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + resultSelector.Print())); + return null; } /// @@ -404,12 +404,16 @@ protected override ShapedQueryExpression TranslateLongCount(ShapedQueryExpressio || selectExpression.Limit != null || selectExpression.Offset != null) { - throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print())); + return null; } if (predicate != null) { source = TranslateWhere(source, predicate); + if (source == null) + { + return null; + } } var translation = _sqlExpressionFactory.ApplyDefaultTypeMapping( @@ -439,7 +443,7 @@ protected override ShapedQueryExpression TranslateMax(ShapedQueryExpression sour || selectExpression.Limit != null || selectExpression.Offset != null) { - throw new InvalidOperationException(CoreStrings.TranslationFailed(selector.Print())); + return null; } if (selector != null) @@ -467,7 +471,7 @@ protected override ShapedQueryExpression TranslateMin(ShapedQueryExpression sour || selectExpression.Limit != null || selectExpression.Offset != null) { - throw new InvalidOperationException(CoreStrings.TranslationFailed(selector.Print())); + return null; } if (selector != null) @@ -490,7 +494,7 @@ protected override ShapedQueryExpression TranslateMin(ShapedQueryExpression sour /// protected override ShapedQueryExpression TranslateOfType(ShapedQueryExpression source, Type resultType) { - throw new InvalidOperationException(CoreStrings.TranslationFailed(source.Print())); + return null; } /// @@ -509,7 +513,7 @@ protected override ShapedQueryExpression TranslateOrderBy(ShapedQueryExpression return source; } - throw new InvalidOperationException(CoreStrings.TranslationFailed(keySelector.Print())); + return null; } /// @@ -520,7 +524,7 @@ protected override ShapedQueryExpression TranslateOrderBy(ShapedQueryExpression /// protected override ShapedQueryExpression TranslateReverse(ShapedQueryExpression source) { - throw new InvalidOperationException(CoreStrings.TranslationFailed(source.Print())); + return null; } /// @@ -539,7 +543,7 @@ protected override ShapedQueryExpression TranslateSelect(ShapedQueryExpression s var selectExpression = (SelectExpression)source.QueryExpression; if (selectExpression.IsDistinct) { - throw new InvalidOperationException(CoreStrings.TranslationFailed(selector.Print())); + return null; } var newSelectorBody = ReplacingExpressionVisitor.Replace(selector.Parameters.Single(), source.ShaperExpression, selector.Body); @@ -558,8 +562,7 @@ protected override ShapedQueryExpression TranslateSelect(ShapedQueryExpression s /// protected override ShapedQueryExpression TranslateSelectMany(ShapedQueryExpression source, LambdaExpression collectionSelector, LambdaExpression resultSelector) { - throw new InvalidOperationException(CoreStrings.TranslationFailed( - collectionSelector.Print() + "; " + resultSelector.Print())); + return null; } /// @@ -570,7 +573,7 @@ protected override ShapedQueryExpression TranslateSelectMany(ShapedQueryExpressi /// protected override ShapedQueryExpression TranslateSelectMany(ShapedQueryExpression source, LambdaExpression selector) { - throw new InvalidOperationException(CoreStrings.TranslationFailed(selector.Print())); + return null; } /// @@ -584,6 +587,10 @@ protected override ShapedQueryExpression TranslateSingleOrDefault(ShapedQueryExp if (predicate != null) { source = TranslateWhere(source, predicate); + if (source == null) + { + return null; + } } var selectExpression = (SelectExpression)source.QueryExpression; @@ -615,7 +622,7 @@ protected override ShapedQueryExpression TranslateSkip(ShapedQueryExpression sou return source; } - throw new InvalidOperationException(CoreStrings.TranslationFailed(count.Print())); + return null; } /// @@ -626,7 +633,7 @@ protected override ShapedQueryExpression TranslateSkip(ShapedQueryExpression sou /// protected override ShapedQueryExpression TranslateSkipWhile(ShapedQueryExpression source, LambdaExpression predicate) { - throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print())); + return null; } /// @@ -642,7 +649,7 @@ protected override ShapedQueryExpression TranslateSum(ShapedQueryExpression sour || selectExpression.Limit != null || selectExpression.Offset != null) { - throw new InvalidOperationException(CoreStrings.TranslationFailed(selector.Print())); + return null; } if (selector != null) @@ -677,7 +684,7 @@ protected override ShapedQueryExpression TranslateTake(ShapedQueryExpression sou return source; } - throw new InvalidOperationException(CoreStrings.TranslationFailed(count.Print())); + return null; } /// @@ -688,7 +695,7 @@ protected override ShapedQueryExpression TranslateTake(ShapedQueryExpression sou /// protected override ShapedQueryExpression TranslateTakeWhile(ShapedQueryExpression source, LambdaExpression predicate) { - throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print())); + return null; } /// @@ -707,7 +714,7 @@ protected override ShapedQueryExpression TranslateThenBy(ShapedQueryExpression s return source; } - throw new InvalidOperationException(CoreStrings.TranslationFailed(keySelector.Print())); + return null; } /// @@ -718,8 +725,7 @@ protected override ShapedQueryExpression TranslateThenBy(ShapedQueryExpression s /// protected override ShapedQueryExpression TranslateUnion(ShapedQueryExpression source1, ShapedQueryExpression source2) { - throw new InvalidOperationException(CoreStrings.TranslationFailed( - source1.Print() + "; " + source2.Print())); + return null; } /// @@ -738,7 +744,7 @@ protected override ShapedQueryExpression TranslateWhere(ShapedQueryExpression so return source; } - throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print())); + return null; } private SqlExpression TranslateExpression(Expression expression) diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs index 5421394e391..f02f4a449c3 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs @@ -292,7 +292,7 @@ protected override Expression VisitExtension(Expression extensionExpression) } default: - throw new InvalidOperationException(CoreStrings.QueryFailed(extensionExpression.Print(), GetType().Name)); + return null; } } diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs index 6f5d46baf7a..46392f752cb 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs @@ -63,12 +63,17 @@ protected override ShapedQueryExpression CreateShapedQueryExpression(Type elemen protected override ShapedQueryExpression TranslateAll(ShapedQueryExpression source, LambdaExpression predicate) { var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression; + predicate = TranslateLambdaExpression(source, predicate); + if (predicate == null) + { + return null; + } inMemoryQueryExpression.ServerQueryExpression = Expression.Call( InMemoryLinqOperatorProvider.All.MakeGenericMethod(typeof(ValueBuffer)), inMemoryQueryExpression.ServerQueryExpression, - TranslateLambdaExpression(source, predicate)); + predicate); source.ShaperExpression = inMemoryQueryExpression.GetSingleScalarProjection(); @@ -79,14 +84,25 @@ protected override ShapedQueryExpression TranslateAny(ShapedQueryExpression sour { var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression; - inMemoryQueryExpression.ServerQueryExpression = predicate == null - ? Expression.Call( + if (predicate == null) + { + inMemoryQueryExpression.ServerQueryExpression = Expression.Call( InMemoryLinqOperatorProvider.Any.MakeGenericMethod(typeof(ValueBuffer)), - inMemoryQueryExpression.ServerQueryExpression) - : Expression.Call( + inMemoryQueryExpression.ServerQueryExpression); + } + else + { + predicate = TranslateLambdaExpression(source, predicate); + if (predicate == null) + { + return null; + } + + inMemoryQueryExpression.ServerQueryExpression = Expression.Call( InMemoryLinqOperatorProvider.AnyPredicate.MakeGenericMethod(typeof(ValueBuffer)), inMemoryQueryExpression.ServerQueryExpression, - TranslateLambdaExpression(source, predicate)); + predicate); + } source.ShaperExpression = inMemoryQueryExpression.GetSingleScalarProjection(); @@ -114,8 +130,11 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s protected override ShapedQueryExpression TranslateContains(ShapedQueryExpression source, Expression item) { var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression; - item = TranslateExpression(item); + if (item == null) + { + return null; + } inMemoryQueryExpression.ServerQueryExpression = Expression.Call( @@ -145,11 +164,17 @@ protected override ShapedQueryExpression TranslateCount(ShapedQueryExpression so } else { + predicate = TranslateLambdaExpression(source, predicate); + if (predicate == null) + { + return null; + } + inMemoryQueryExpression.ServerQueryExpression = Expression.Call( InMemoryLinqOperatorProvider.CountPredicate.MakeGenericMethod(typeof(ValueBuffer)), inMemoryQueryExpression.ServerQueryExpression, - TranslateLambdaExpression(source, predicate)); + predicate); } source.ShaperExpression = inMemoryQueryExpression.GetSingleScalarProjection(); @@ -203,6 +228,10 @@ protected override ShapedQueryExpression TranslateJoin(ShapedQueryExpression out { outerKeySelector = TranslateLambdaExpression(outer, outerKeySelector); innerKeySelector = TranslateLambdaExpression(inner, innerKeySelector); + if (outerKeySelector == null || innerKeySelector == null) + { + return null; + } var transparentIdentifierType = TransparentIdentifierFactory.Create( resultSelector.Parameters[0].Type, @@ -236,6 +265,10 @@ protected override ShapedQueryExpression TranslateLeftJoin(ShapedQueryExpression { outerKeySelector = TranslateLambdaExpression(outer, outerKeySelector); innerKeySelector = TranslateLambdaExpression(inner, innerKeySelector); + if (outerKeySelector == null || innerKeySelector == null) + { + return null; + } var transparentIdentifierType = TransparentIdentifierFactory.Create( resultSelector.Parameters[0].Type, @@ -267,11 +300,17 @@ protected override ShapedQueryExpression TranslateLongCount(ShapedQueryExpressio } else { + predicate = TranslateLambdaExpression(source, predicate); + if (predicate == null) + { + return null; + } + inMemoryQueryExpression.ServerQueryExpression = Expression.Call( InMemoryLinqOperatorProvider.LongCountPredicate.MakeGenericMethod(typeof(ValueBuffer)), inMemoryQueryExpression.ServerQueryExpression, - TranslateLambdaExpression(source, predicate)); + predicate); } source.ShaperExpression = inMemoryQueryExpression.GetSingleScalarProjection(); @@ -329,14 +368,16 @@ protected override ShapedQueryExpression TranslateOfType(ShapedQueryExpression s Expression.Constant(derivedDerivedType.GetDiscriminatorValue(), discriminatorProperty.ClrType))); } - var predicate = Expression.Lambda( - equals, - parameter); + var predicate = TranslateLambdaExpression(source, Expression.Lambda(equals, parameter)); + if (predicate == null) + { + return null; + } inMemoryQueryExpression.ServerQueryExpression = Expression.Call( InMemoryLinqOperatorProvider.Where.MakeGenericMethod(typeof(ValueBuffer)), inMemoryQueryExpression.ServerQueryExpression, - TranslateLambdaExpression(source, predicate)); + predicate); source.ShaperExpression = entityShaperExpression.WithEntityType(derivedType); @@ -352,6 +393,10 @@ protected override ShapedQueryExpression TranslateOrderBy(ShapedQueryExpression var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression; keySelector = TranslateLambdaExpression(source, keySelector); + if (keySelector == null) + { + return null; + } inMemoryQueryExpression.ServerQueryExpression = Expression.Call( @@ -472,12 +517,17 @@ protected override ShapedQueryExpression TranslateSingleOrDefault(ShapedQueryExp protected override ShapedQueryExpression TranslateSkip(ShapedQueryExpression source, Expression count) { var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression; + count = TranslateExpression(count); + if (count == null) + { + return null; + } inMemoryQueryExpression.ServerQueryExpression = Expression.Call( InMemoryLinqOperatorProvider.Skip.MakeGenericMethod(typeof(ValueBuffer)), inMemoryQueryExpression.ServerQueryExpression, - TranslateExpression(count)); + count); return source; } @@ -491,12 +541,17 @@ protected override ShapedQueryExpression TranslateSum(ShapedQueryExpression sour protected override ShapedQueryExpression TranslateTake(ShapedQueryExpression source, Expression count) { var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression; + count = TranslateExpression(count); + if (count == null) + { + return null; + } inMemoryQueryExpression.ServerQueryExpression = Expression.Call( InMemoryLinqOperatorProvider.Take.MakeGenericMethod(typeof(ValueBuffer)), inMemoryQueryExpression.ServerQueryExpression, - TranslateExpression(count)); + count); return source; } @@ -507,8 +562,11 @@ protected override ShapedQueryExpression TranslateTakeWhile(ShapedQueryExpressio protected override ShapedQueryExpression TranslateThenBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending) { var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression; - keySelector = TranslateLambdaExpression(source, keySelector); + if (keySelector == null) + { + return null; + } inMemoryQueryExpression.ServerQueryExpression = Expression.Call( @@ -526,10 +584,16 @@ protected override ShapedQueryExpression TranslateUnion(ShapedQueryExpression so protected override ShapedQueryExpression TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate) { var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression; + predicate = TranslateLambdaExpression(source, predicate); + if (predicate == null) + { + return null; + } + inMemoryQueryExpression.ServerQueryExpression = Expression.Call( InMemoryLinqOperatorProvider.Where.MakeGenericMethod(typeof(ValueBuffer)), inMemoryQueryExpression.ServerQueryExpression, - TranslateLambdaExpression(source, predicate)); + predicate); return source; } @@ -544,9 +608,12 @@ private LambdaExpression TranslateLambdaExpression( { var lambdaBody = ReplacingExpressionVisitor.Replace( lambdaExpression.Parameters.Single(), shapedQueryExpression.ShaperExpression, lambdaExpression.Body); + lambdaBody = TranslateExpression(lambdaBody); - return Expression.Lambda(TranslateExpression(lambdaBody), - ((InMemoryQueryExpression)shapedQueryExpression.QueryExpression).ValueBufferParameter); + return lambdaBody != null + ? Expression.Lambda(lambdaBody, + ((InMemoryQueryExpression)shapedQueryExpression.QueryExpression).ValueBufferParameter) + : null; } private ShapedQueryExpression TranslateScalarAggregate( @@ -561,6 +628,11 @@ private ShapedQueryExpression TranslateScalarAggregate( inMemoryQueryExpression.ValueBufferParameter) : TranslateLambdaExpression(source, selector); + if (selector == null) + { + return null; + } + inMemoryQueryExpression.ServerQueryExpression = Expression.Call( InMemoryLinqOperatorProvider @@ -583,6 +655,11 @@ private ShapedQueryExpression TranslateSingleResultOperator( ? Expression.Lambda(Expression.Constant(true), Expression.Parameter(typeof(ValueBuffer))) : TranslateLambdaExpression(source, predicate); + if (predicate == null) + { + return null; + } + inMemoryQueryExpression.ServerQueryExpression = Expression.Call( method.MakeGenericMethod(typeof(ValueBuffer)), diff --git a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs index 0d6249ffd8a..ac9d7da97af 100644 --- a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs @@ -105,26 +105,25 @@ private static ShapedQueryExpression CreateShapedQueryExpression(IEntityType ent protected override ShapedQueryExpression TranslateAll(ShapedQueryExpression source, LambdaExpression predicate) { var translation = TranslateLambdaExpression(source, predicate); - - if (translation != null) + if (translation == null) { - var selectExpression = (SelectExpression)source.QueryExpression; - selectExpression.ApplyPredicate(_sqlExpressionFactory.Not(translation)); - selectExpression.ReplaceProjectionMapping(new Dictionary()); - if (selectExpression.Limit == null - && selectExpression.Offset == null) - { - selectExpression.ClearOrdering(); - } - - translation = _sqlExpressionFactory.Exists(selectExpression, true); - source.QueryExpression = _sqlExpressionFactory.Select(translation); - source.ShaperExpression = new ProjectionBindingExpression(source.QueryExpression, new ProjectionMember(), typeof(bool)); + return null; + } - return source; + var selectExpression = (SelectExpression)source.QueryExpression; + selectExpression.ApplyPredicate(_sqlExpressionFactory.Not(translation)); + selectExpression.ReplaceProjectionMapping(new Dictionary()); + if (selectExpression.Limit == null + && selectExpression.Offset == null) + { + selectExpression.ClearOrdering(); } - throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print())); + translation = _sqlExpressionFactory.Exists(selectExpression, true); + source.QueryExpression = _sqlExpressionFactory.Select(translation); + source.ShaperExpression = new ProjectionBindingExpression(source.QueryExpression, new ProjectionMember(), typeof(bool)); + + return source; } protected override ShapedQueryExpression TranslateAny(ShapedQueryExpression source, LambdaExpression predicate) @@ -132,6 +131,10 @@ protected override ShapedQueryExpression TranslateAny(ShapedQueryExpression sour if (predicate != null) { source = TranslateWhere(source, predicate); + if (source == null) + { + return null; + } } var selectExpression = (SelectExpression)source.QueryExpression; @@ -160,24 +163,18 @@ protected override ShapedQueryExpression TranslateAverage(ShapedQueryExpression : RemapLambdaBody(source, selector); var projection = _sqlTranslator.TranslateAverage(newSelector); - - if (projection == null) - { - throw new InvalidOperationException(CoreStrings.TranslationFailed(selectExpression.Print())); - } - - return AggregateResultShaper(source, projection, throwOnNullResult: true, resultType); + return projection != null + ? AggregateResultShaper(source, projection, throwOnNullResult: true, resultType) + : null; } protected override ShapedQueryExpression TranslateCast(ShapedQueryExpression source, Type resultType) { - if (source.ShaperExpression.Type == resultType) + if (source.ShaperExpression.Type != resultType) { - return source; + source.ShaperExpression = Expression.Convert(source.ShaperExpression, resultType); } - source.ShaperExpression = Expression.Convert(source.ShaperExpression, resultType); - return source; } @@ -192,24 +189,23 @@ protected override ShapedQueryExpression TranslateContains(ShapedQueryExpression { var selectExpression = (SelectExpression)source.QueryExpression; var translation = TranslateExpression(item); - - if (translation != null) + if (translation == null) { - if (selectExpression.Limit == null - && selectExpression.Offset == null) - { - selectExpression.ClearOrdering(); - } - - selectExpression.ApplyProjection(); - translation = _sqlExpressionFactory.In(translation, selectExpression, false); - source.QueryExpression = _sqlExpressionFactory.Select(translation); - source.ShaperExpression = new ProjectionBindingExpression(source.QueryExpression, new ProjectionMember(), typeof(bool)); + return null; + } - return source; + if (selectExpression.Limit == null + && selectExpression.Offset == null) + { + selectExpression.ClearOrdering(); } - throw new InvalidOperationException(CoreStrings.TranslationFailed(item.Print())); + selectExpression.ApplyProjection(); + translation = _sqlExpressionFactory.In(translation, selectExpression, false); + source.QueryExpression = _sqlExpressionFactory.Select(translation); + source.ShaperExpression = new ProjectionBindingExpression(source.QueryExpression, new ProjectionMember(), typeof(bool)); + + return source; } protected override ShapedQueryExpression TranslateCount(ShapedQueryExpression source, LambdaExpression predicate) @@ -220,9 +216,17 @@ protected override ShapedQueryExpression TranslateCount(ShapedQueryExpression so if (predicate != null) { source = TranslateWhere(source, predicate); + if (source == null) + { + return null; + } } var translation = _sqlTranslator.TranslateCount(); + if (translation == null) + { + return null; + } var projectionMapping = new Dictionary { @@ -246,7 +250,7 @@ protected override ShapedQueryExpression TranslateDefaultIfEmpty(ShapedQueryExpr return source; } - throw new InvalidOperationException(CoreStrings.TranslationFailed(defaultValue.Print())); + return null; } protected override ShapedQueryExpression TranslateDistinct(ShapedQueryExpression source) @@ -257,7 +261,7 @@ protected override ShapedQueryExpression TranslateDistinct(ShapedQueryExpression } protected override ShapedQueryExpression TranslateElementAtOrDefault(ShapedQueryExpression source, Expression index, bool returnDefault) - => throw new InvalidOperationException(CoreStrings.TranslationFailed(index.Print())); + => null; protected override ShapedQueryExpression TranslateExcept(ShapedQueryExpression source1, ShapedQueryExpression source2) { @@ -270,6 +274,10 @@ protected override ShapedQueryExpression TranslateFirstOrDefault(ShapedQueryExpr if (predicate != null) { source = TranslateWhere(source, predicate); + if (source == null) + { + return null; + } } var selectExpression = (SelectExpression)source.QueryExpression; @@ -330,8 +338,7 @@ protected override ShapedQueryExpression TranslateGroupBy( return source; } - throw new InvalidOperationException(CoreStrings.TranslationFailed( - keySelector.Print() + "; " + elementSelector.Print() + "; " + resultSelector.Print())); + return null; } private Expression TranslateGroupingKey(Expression expression) @@ -380,10 +387,9 @@ private Expression TranslateGroupingKey(Expression expression) default: var translation = _sqlTranslator.Translate(expression); - if (translation == null) { - throw new InvalidOperationException(CoreStrings.TranslationFailed(expression.Print())); + return null; } return translation.Type == expression.Type @@ -434,9 +440,7 @@ protected override ShapedQueryExpression TranslateGroupJoin(ShapedQueryExpressio // innerTransparentIdentifierType); //} - // See #17236 - throw new InvalidOperationException(CoreStrings.TranslationFailed( - outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + resultSelector.Print())); + return null; } protected override ShapedQueryExpression TranslateIntersect(ShapedQueryExpression source1, ShapedQueryExpression source2) @@ -469,12 +473,15 @@ protected override ShapedQueryExpression TranslateJoin( transparentIdentifierType); } - // See #17236 - throw new InvalidOperationException(CoreStrings.TranslationFailed( - outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + resultSelector.Print())); + return null; } - protected override ShapedQueryExpression TranslateLeftJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector) + protected override ShapedQueryExpression TranslateLeftJoin( + ShapedQueryExpression outer, + ShapedQueryExpression inner, + LambdaExpression outerKeySelector, + LambdaExpression innerKeySelector, + LambdaExpression resultSelector) { var joinPredicate = CreateJoinPredicate(outer, outerKeySelector, inner, innerKeySelector); if (joinPredicate != null) @@ -493,9 +500,7 @@ protected override ShapedQueryExpression TranslateLeftJoin(ShapedQueryExpression transparentIdentifierType); } - // See #17236 - throw new InvalidOperationException(CoreStrings.TranslationFailed( - outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + resultSelector.Print())); + return null; } private SqlBinaryExpression CreateJoinPredicate( @@ -562,6 +567,10 @@ protected override ShapedQueryExpression TranslateLastOrDefault( if (predicate != null) { source = TranslateWhere(source, predicate); + if (source == null) + { + return null; + } } selectExpression.ReverseOrderings(); @@ -583,9 +592,18 @@ protected override ShapedQueryExpression TranslateLongCount(ShapedQueryExpressio if (predicate != null) { source = TranslateWhere(source, predicate); + if (source == null) + { + return null; + } } var translation = _sqlTranslator.TranslateLongCount(); + if (translation == null) + { + return null; + } + var projectionMapping = new Dictionary { { new ProjectionMember(), translation } @@ -692,18 +710,18 @@ protected override ShapedQueryExpression TranslateOfType(ShapedQueryExpression s protected override ShapedQueryExpression TranslateOrderBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending) { var translation = TranslateLambdaExpression(source, keySelector); - if (translation != null) + if (translation == null) { - ((SelectExpression)source.QueryExpression).ApplyOrdering(new OrderingExpression(translation, ascending)); - - return source; + return null; } - throw new InvalidOperationException(CoreStrings.TranslationFailed(keySelector.Print())); + ((SelectExpression)source.QueryExpression).ApplyOrdering(new OrderingExpression(translation, ascending)); + + return source; } protected override ShapedQueryExpression TranslateReverse(ShapedQueryExpression source) - => throw new InvalidOperationException(CoreStrings.TranslationFailed(source.Print())); + => null; protected override ShapedQueryExpression TranslateSelect(ShapedQueryExpression source, LambdaExpression selector) { @@ -766,6 +784,10 @@ protected override ShapedQueryExpression TranslateSelectMany( if (defaultIfEmpty) { inner = TranslateDefaultIfEmpty(inner, null); + if (inner == null) + { + return null; + } } var transparentIdentifierType = TransparentIdentifierFactory.Create( @@ -783,9 +805,7 @@ protected override ShapedQueryExpression TranslateSelectMany( } } - // See #17236 - throw new InvalidOperationException(CoreStrings.TranslationFailed( - collectionSelector.Print() + "; " + resultSelector.Print())); + return null; } private class CorrelationFindingExpressionVisitor : ExpressionVisitor @@ -849,6 +869,10 @@ protected override ShapedQueryExpression TranslateSingleOrDefault(ShapedQueryExp if (predicate != null) { source = TranslateWhere(source, predicate); + if (source == null) + { + return null; + } } var selectExpression = (SelectExpression)source.QueryExpression; @@ -866,19 +890,18 @@ protected override ShapedQueryExpression TranslateSkip(ShapedQueryExpression sou { var selectExpression = (SelectExpression)source.QueryExpression; var translation = TranslateExpression(count); - - if (translation != null) + if (translation == null) { - selectExpression.ApplyOffset(translation); - - return source; + return null; } - throw new InvalidOperationException(CoreStrings.TranslationFailed(count.Print())); + selectExpression.ApplyOffset(translation); + + return source; } protected override ShapedQueryExpression TranslateSkipWhile(ShapedQueryExpression source, LambdaExpression predicate) - => throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print())); + => null; protected override ShapedQueryExpression TranslateSum(ShapedQueryExpression source, LambdaExpression selector, Type resultType) { @@ -890,44 +913,39 @@ protected override ShapedQueryExpression TranslateSum(ShapedQueryExpression sour : RemapLambdaBody(source, selector); var projection = _sqlTranslator.TranslateSum(newSelector); - - if (projection == null) - { - throw new InvalidOperationException(CoreStrings.TranslationFailed(selectExpression.Print())); - } - - return AggregateResultShaper(source, projection, throwOnNullResult: false, resultType); + return projection != null + ? AggregateResultShaper(source, projection, throwOnNullResult: false, resultType) + : null; } protected override ShapedQueryExpression TranslateTake(ShapedQueryExpression source, Expression count) { var selectExpression = (SelectExpression)source.QueryExpression; var translation = TranslateExpression(count); - - if (translation != null) + if (translation == null) { - selectExpression.ApplyLimit(translation); - - return source; + return null; } - throw new InvalidOperationException(CoreStrings.TranslationFailed(count.Print())); + selectExpression.ApplyLimit(translation); + + return source; } protected override ShapedQueryExpression TranslateTakeWhile(ShapedQueryExpression source, LambdaExpression predicate) - => throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print())); + => null; protected override ShapedQueryExpression TranslateThenBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending) { var translation = TranslateLambdaExpression(source, keySelector); - if (translation != null) + if (translation == null) { - ((SelectExpression)source.QueryExpression).AppendOrdering(new OrderingExpression(translation, ascending)); - - return source; + return null; } - throw new InvalidOperationException(CoreStrings.TranslationFailed(keySelector.Print())); + ((SelectExpression)source.QueryExpression).AppendOrdering(new OrderingExpression(translation, ascending)); + + return source; } protected override ShapedQueryExpression TranslateUnion(ShapedQueryExpression source1, ShapedQueryExpression source2) @@ -939,28 +957,21 @@ protected override ShapedQueryExpression TranslateUnion(ShapedQueryExpression so protected override ShapedQueryExpression TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate) { var translation = TranslateLambdaExpression(source, predicate); - if (translation != null) + if (translation == null) { - ((SelectExpression)source.QueryExpression).ApplyPredicate(translation); - - return source; + return null; } - throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print())); - } + ((SelectExpression)source.QueryExpression).ApplyPredicate(translation); - private SqlExpression TranslateExpression(Expression expression) - { - return _sqlTranslator.Translate(expression); + return source; } + private SqlExpression TranslateExpression(Expression expression) => _sqlTranslator.Translate(expression); + private SqlExpression TranslateLambdaExpression( ShapedQueryExpression shapedQueryExpression, LambdaExpression lambdaExpression) - { - var lambdaBody = RemapLambdaBody(shapedQueryExpression, lambdaExpression); - - return TranslateExpression(lambdaBody); - } + => TranslateExpression(RemapLambdaBody(shapedQueryExpression, lambdaExpression)); private Expression RemapLambdaBody(ShapedQueryExpression shapedQueryExpression, LambdaExpression lambdaExpression) { @@ -971,11 +982,9 @@ private Expression RemapLambdaBody(ShapedQueryExpression shapedQueryExpression, } internal Expression ExpandWeakEntities(SelectExpression selectExpression, Expression lambdaBody) - { - return _weakEntityExpandingExpressionVisitor.Expand(selectExpression, lambdaBody); - } + => _weakEntityExpandingExpressionVisitor.Expand(selectExpression, lambdaBody); - public class WeakEntityExpandingExpressionVisitor : ExpressionVisitor + private class WeakEntityExpandingExpressionVisitor : ExpressionVisitor { private SelectExpression _selectExpression; private readonly RelationalSqlTranslatingExpressionVisitor _sqlTranslator; @@ -1162,6 +1171,11 @@ private Expression Expand(Expression source, MemberIdentity member) private ShapedQueryExpression AggregateResultShaper( ShapedQueryExpression source, Expression projection, bool throwOnNullResult, Type resultType) { + if (projection == null) + { + return null; + } + var selectExpression = (SelectExpression)source.QueryExpression; selectExpression.ReplaceProjectionMapping( new Dictionary diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteQueryableMethodTranslatingExpressionVisitor.cs index aa551713738..fcf079ad4a0 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteQueryableMethodTranslatingExpressionVisitor.cs @@ -34,6 +34,11 @@ protected override QueryableMethodTranslatingExpressionVisitor CreateSubqueryVis protected override ShapedQueryExpression TranslateOrderBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending) { var translation = base.TranslateOrderBy(source, keySelector, ascending); + if (translation == null) + { + return null; + } + var orderingExpression = ((SelectExpression)translation.QueryExpression).Orderings.Last(); var orderingExpressionType = GetProviderType(orderingExpression.Expression); if (orderingExpressionType == typeof(DateTimeOffset) @@ -51,6 +56,11 @@ protected override ShapedQueryExpression TranslateOrderBy(ShapedQueryExpression protected override ShapedQueryExpression TranslateThenBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending) { var translation = base.TranslateThenBy(source, keySelector, ascending); + if (translation == null) + { + return null; + } + var orderingExpression = ((SelectExpression)translation.QueryExpression).Orderings.Last(); var orderingExpressionType = GetProviderType(orderingExpression.Expression); if (orderingExpressionType == typeof(DateTimeOffset) diff --git a/test/EFCore.Relational.Specification.Tests/Query/QueryNoClientEvalTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/QueryNoClientEvalTestBase.cs index dea268a8426..d7d61fb17f1 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/QueryNoClientEvalTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/QueryNoClientEvalTestBase.cs @@ -12,7 +12,6 @@ // ReSharper disable InconsistentNaming namespace Microsoft.EntityFrameworkCore.Query { -#pragma warning disable CS0612 // Type or member is obsolete public abstract class QueryNoClientEvalTestBase : IClassFixture where TFixture : NorthwindQueryRelationalFixture, new() { @@ -26,10 +25,10 @@ public virtual void Throws_when_where() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon"), - Assert.Throws( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => c.IsLondon)"), + RemoveNewLines(Assert.Throws( () => context.Customers.Where(c => c.IsLondon).ToList()) - .Message); + .Message)); } } @@ -39,9 +38,9 @@ public virtual void Throws_when_orderby() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon"), - Assert.Throws( - () => context.Customers.OrderBy(c => c.IsLondon).ToList()).Message); + CoreStrings.TranslationFailed("OrderBy( source: DbSet, keySelector: (c) => c.IsLondon)"), + RemoveNewLines(Assert.Throws( + () => context.Customers.OrderBy(c => c.IsLondon).ToList()).Message)); } } @@ -51,12 +50,12 @@ public virtual void Throws_when_orderby_multiple() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon"), - Assert.Throws( + CoreStrings.TranslationFailed("OrderBy( source: DbSet, keySelector: (c) => c.IsLondon)"), + RemoveNewLines(Assert.Throws( () => context.Customers .OrderBy(c => c.IsLondon) .ThenBy(c => ClientMethod(c)) - .ToList()).Message); + .ToList()).Message)); } } @@ -69,7 +68,7 @@ public virtual void Throws_when_where_subquery_correlated() { Assert.Equal( CoreStrings.TranslationFailed( - "(c0) => EntityShaperExpression: EntityType: Customer ValueBufferExpression: ProjectionBindingExpression: EmptyProjectionMember IsNullable: False.CustomerID == c0.CustomerID && c0.IsLondon"), + "Any( source: DbSet, predicate: (c0) => EntityShaperExpression: EntityType: Customer ValueBufferExpression: ProjectionBindingExpression: EmptyProjectionMember IsNullable: False .CustomerID == c0.CustomerID && c0.IsLondon)"), RemoveNewLines( Assert.Throws( () => context.Customers @@ -86,9 +85,9 @@ public virtual void Throws_when_all() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon"), - Assert.Throws( - () => context.Customers.All(c => c.IsLondon)).Message); + CoreStrings.TranslationFailed("All( source: DbSet, predicate: (c) => c.IsLondon)"), + RemoveNewLines(Assert.Throws( + () => context.Customers.All(c => c.IsLondon)).Message)); } } @@ -98,12 +97,12 @@ public virtual void Throws_when_from_sql_composed() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon"), - Assert.Throws( + CoreStrings.TranslationFailed("Where( source: FromSqlOnQueryable( source: DbSet, sql: \"select * from \"Customers\"\", parameters: (Unhandled parameter: __p_0)), predicate: (c) => c.IsLondon)"), + RemoveNewLines(Assert.Throws( () => context.Customers .FromSqlRaw(NormalizeDelimetersInRawString("select * from [Customers]")) .Where(c => c.IsLondon) - .ToList()).Message); + .ToList()).Message)); } } @@ -127,15 +126,15 @@ public virtual void Throws_when_subquery_main_from_clause() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon"), - Assert.Throws( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => c.IsLondon)"), + RemoveNewLines(Assert.Throws( () => (from c1 in context.Customers .Where(c => c.IsLondon) .OrderBy(c => c.CustomerID) .Take(5) select c1) - .ToList()).Message); + .ToList()).Message)); } } @@ -146,7 +145,7 @@ public virtual void Throws_when_select_many() { Assert.Equal( CoreStrings.QueryFailed("(c1) => int[] { 1, 2, 3, }", "NavigationExpandingExpressionVisitor"), - Assert.Throws( + RemoveNewLines(Assert.Throws( () => (from c1 in context.Customers from i in new[] @@ -154,7 +153,7 @@ from i in new[] 1, 2, 3 } select c1) - .ToList()).Message); + .ToList()).Message)); } } @@ -210,10 +209,10 @@ public virtual void Throws_when_group_by() .ToList(); Assert.Equal( CoreStrings.TranslationFailed("GroupBy([c].CustomerID, [c])"), - Assert.Throws( + RemoveNewLines(Assert.Throws( () => context.Customers .GroupBy(c => c.CustomerID) - .ToList()).Message); + .ToList()).Message)); } } @@ -223,9 +222,9 @@ public virtual void Throws_when_first() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon"), - Assert.Throws( - () => context.Customers.First(c => c.IsLondon)).Message); + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => c.IsLondon)"), + RemoveNewLines(Assert.Throws( + () => context.Customers.First(c => c.IsLondon)).Message)); } } @@ -235,9 +234,9 @@ public virtual void Throws_when_single() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon"), - Assert.Throws( - () => context.Customers.Single(c => c.IsLondon)).Message); + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => c.IsLondon)"), + RemoveNewLines(Assert.Throws( + () => context.Customers.Single(c => c.IsLondon)).Message)); } } @@ -247,9 +246,9 @@ public virtual void Throws_when_first_or_default() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon"), - Assert.Throws( - () => context.Customers.FirstOrDefault(c => c.IsLondon)).Message); + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => c.IsLondon)"), + RemoveNewLines(Assert.Throws( + () => context.Customers.FirstOrDefault(c => c.IsLondon)).Message)); } } @@ -259,9 +258,9 @@ public virtual void Throws_when_single_or_default() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon"), - Assert.Throws( - () => context.Customers.SingleOrDefault(c => c.IsLondon)).Message); + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => c.IsLondon)"), + RemoveNewLines(Assert.Throws( + () => context.Customers.SingleOrDefault(c => c.IsLondon)).Message)); } } @@ -276,5 +275,4 @@ private FormattableString NormalizeDelimetersInInterpolatedString(FormattableStr protected NorthwindContext CreateContext() => Fixture.CreateContext(); } -#pragma warning restore CS0612 // Type or member is obsolete } diff --git a/test/EFCore.Relational.Specification.Tests/Query/UdfDbFunctionTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/UdfDbFunctionTestBase.cs index 4840c17e8d4..74178ea1509 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/UdfDbFunctionTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/UdfDbFunctionTestBase.cs @@ -614,11 +614,11 @@ public virtual void Scalar_Nested_Function_Unwind_Client_Eval_Where_Static() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => 2 == AddOneStatic(c.Id)"), - Assert.Throws( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => 2 == AddOneStatic(c.Id))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 2 == UDFSqlContext.AddOneStatic(c.Id) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -628,11 +628,11 @@ public virtual void Scalar_Nested_Function_Unwind_Client_Eval_OrderBy_Static() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => AddOneStatic(c.Id)"), - Assert.Throws( + CoreStrings.TranslationFailed("OrderBy( source: DbSet, keySelector: (c) => AddOneStatic(c.Id))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers orderby UDFSqlContext.AddOneStatic(c.Id) - select c.Id).ToList()).Message); + select c.Id).ToList()).Message)); } } @@ -657,11 +657,11 @@ public virtual void Scalar_Nested_Function_Client_BCL_UDF_Static() { Assert.Equal( CoreStrings.TranslationFailed( - "(c) => 2 == AddOneStatic(Abs(CustomerOrderCountWithClientStatic(c.Id)))"), - Assert.Throws( + "Where( source: DbSet, predicate: (c) => 2 == AddOneStatic(Abs(CustomerOrderCountWithClientStatic(c.Id))))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 2 == UDFSqlContext.AddOneStatic(Math.Abs(UDFSqlContext.CustomerOrderCountWithClientStatic(c.Id))) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -672,11 +672,11 @@ public virtual void Scalar_Nested_Function_Client_UDF_BCL_Static() { Assert.Equal( CoreStrings.TranslationFailed( - "(c) => 2 == AddOneStatic(CustomerOrderCountWithClientStatic(Abs(c.Id)))"), - Assert.Throws( + "Where( source: DbSet, predicate: (c) => 2 == AddOneStatic(CustomerOrderCountWithClientStatic(Abs(c.Id))))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 2 == UDFSqlContext.AddOneStatic(UDFSqlContext.CustomerOrderCountWithClientStatic(Math.Abs(c.Id))) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -687,11 +687,11 @@ public virtual void Scalar_Nested_Function_BCL_Client_UDF_Static() { Assert.Equal( CoreStrings.TranslationFailed( - "(c) => 2 == Abs(AddOneStatic(CustomerOrderCountWithClientStatic(c.Id)))"), - Assert.Throws( + "Where( source: DbSet, predicate: (c) => 2 == Abs(AddOneStatic(CustomerOrderCountWithClientStatic(c.Id))))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 2 == Math.Abs(UDFSqlContext.AddOneStatic(UDFSqlContext.CustomerOrderCountWithClientStatic(c.Id))) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -702,11 +702,11 @@ public virtual void Scalar_Nested_Function_BCL_UDF_Client_Static() { Assert.Equal( CoreStrings.TranslationFailed( - "(c) => 1 == Abs(CustomerOrderCountWithClientStatic(AddOneStatic(c.Id)))"), - Assert.Throws( + "Where( source: DbSet, predicate: (c) => 1 == Abs(CustomerOrderCountWithClientStatic(AddOneStatic(c.Id))))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 1 == Math.Abs(UDFSqlContext.CustomerOrderCountWithClientStatic(UDFSqlContext.AddOneStatic(c.Id))) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -717,11 +717,11 @@ public virtual void Scalar_Nested_Function_UDF_BCL_Client_Static() { Assert.Equal( CoreStrings.TranslationFailed( - "(c) => 1 == CustomerOrderCountWithClientStatic(Abs(AddOneStatic(c.Id)))"), - Assert.Throws( + "Where( source: DbSet, predicate: (c) => 1 == CustomerOrderCountWithClientStatic(Abs(AddOneStatic(c.Id))))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 1 == UDFSqlContext.CustomerOrderCountWithClientStatic(Math.Abs(UDFSqlContext.AddOneStatic(c.Id))) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -732,11 +732,11 @@ public virtual void Scalar_Nested_Function_UDF_Client_BCL_Static() { Assert.Equal( CoreStrings.TranslationFailed( - "(c) => 1 == CustomerOrderCountWithClientStatic(AddOneStatic(Abs(c.Id)))"), - Assert.Throws( + "Where( source: DbSet, predicate: (c) => 1 == CustomerOrderCountWithClientStatic(AddOneStatic(Abs(c.Id))))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 1 == UDFSqlContext.CustomerOrderCountWithClientStatic(UDFSqlContext.AddOneStatic(Math.Abs(c.Id))) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -746,11 +746,11 @@ public virtual void Scalar_Nested_Function_Client_BCL_Static() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => 3 == AddOneStatic(Abs(c.Id))"), - Assert.Throws( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => 3 == AddOneStatic(Abs(c.Id)))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 3 == UDFSqlContext.AddOneStatic(Math.Abs(c.Id)) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -760,11 +760,11 @@ public virtual void Scalar_Nested_Function_Client_UDF_Static() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => 2 == AddOneStatic(CustomerOrderCountWithClientStatic(c.Id))"), - Assert.Throws( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => 2 == AddOneStatic(CustomerOrderCountWithClientStatic(c.Id)))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 2 == UDFSqlContext.AddOneStatic(UDFSqlContext.CustomerOrderCountWithClientStatic(c.Id)) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -774,11 +774,11 @@ public virtual void Scalar_Nested_Function_BCL_Client_Static() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => 3 == Abs(AddOneStatic(c.Id))"), - Assert.Throws( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => 3 == Abs(AddOneStatic(c.Id)))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 3 == Math.Abs(UDFSqlContext.AddOneStatic(c.Id)) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -801,11 +801,11 @@ public virtual void Scalar_Nested_Function_UDF_Client_Static() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => 2 == CustomerOrderCountWithClientStatic(AddOneStatic(c.Id))"), - Assert.Throws( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => 2 == CustomerOrderCountWithClientStatic(AddOneStatic(c.Id)))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 2 == UDFSqlContext.CustomerOrderCountWithClientStatic(UDFSqlContext.AddOneStatic(c.Id)) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -1134,11 +1134,11 @@ public virtual void Scalar_Nested_Function_Unwind_Client_Eval_Where_Instance() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => 2 == (Unhandled parameter: __context_0).AddOneInstance(c.Id)"), - Assert.Throws( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => 2 == (Unhandled parameter: __context_0).AddOneInstance(c.Id))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 2 == context.AddOneInstance(c.Id) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -1148,11 +1148,11 @@ public virtual void Scalar_Nested_Function_Unwind_Client_Eval_OrderBy_Instance() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => (Unhandled parameter: __context_0).AddOneInstance(c.Id)"), - Assert.Throws( + CoreStrings.TranslationFailed("OrderBy( source: DbSet, keySelector: (c) => (Unhandled parameter: __context_0).AddOneInstance(c.Id))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers orderby context.AddOneInstance(c.Id) - select c.Id).ToList()).Message); + select c.Id).ToList()).Message)); } } @@ -1177,11 +1177,11 @@ public virtual void Scalar_Nested_Function_Client_BCL_UDF_Instance() { Assert.Equal( CoreStrings.TranslationFailed( - "(c) => 2 == (Unhandled parameter: __context_0).AddOneInstance(Abs((Unhandled parameter: __context_0).CustomerOrderCountWithClientInstance(c.Id)))"), - Assert.Throws( + "Where( source: DbSet, predicate: (c) => 2 == (Unhandled parameter: __context_0).AddOneInstance(Abs((Unhandled parameter: __context_0).CustomerOrderCountWithClientInstance(c.Id))))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 2 == context.AddOneInstance(Math.Abs(context.CustomerOrderCountWithClientInstance(c.Id))) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -1192,11 +1192,11 @@ public virtual void Scalar_Nested_Function_Client_UDF_BCL_Instance() { Assert.Equal( CoreStrings.TranslationFailed( - "(c) => 2 == (Unhandled parameter: __context_0).AddOneInstance((Unhandled parameter: __context_0).CustomerOrderCountWithClientInstance(Abs(c.Id)))"), - Assert.Throws( + "Where( source: DbSet, predicate: (c) => 2 == (Unhandled parameter: __context_0).AddOneInstance((Unhandled parameter: __context_0).CustomerOrderCountWithClientInstance(Abs(c.Id))))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 2 == context.AddOneInstance(context.CustomerOrderCountWithClientInstance(Math.Abs(c.Id))) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -1206,11 +1206,11 @@ public virtual void Scalar_Nested_Function_BCL_Client_UDF_Instance() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => 2 == Abs((Unhandled parameter: __context_0).AddOneInstance((Unhandled parameter: __context_0).CustomerOrderCountWithClientInstance(c.Id)))"), - Assert.Throws( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => 2 == Abs((Unhandled parameter: __context_0).AddOneInstance((Unhandled parameter: __context_0).CustomerOrderCountWithClientInstance(c.Id))))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 2 == Math.Abs(context.AddOneInstance(context.CustomerOrderCountWithClientInstance(c.Id))) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -1221,11 +1221,11 @@ public virtual void Scalar_Nested_Function_BCL_UDF_Client_Instance() { Assert.Equal( CoreStrings.TranslationFailed( - "(c) => 1 == Abs((Unhandled parameter: __context_0).CustomerOrderCountWithClientInstance((Unhandled parameter: __context_0).AddOneInstance(c.Id)))"), - Assert.Throws( + "Where( source: DbSet, predicate: (c) => 1 == Abs((Unhandled parameter: __context_0).CustomerOrderCountWithClientInstance((Unhandled parameter: __context_0).AddOneInstance(c.Id))))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 1 == Math.Abs(context.CustomerOrderCountWithClientInstance(context.AddOneInstance(c.Id))) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -1236,11 +1236,11 @@ public virtual void Scalar_Nested_Function_UDF_BCL_Client_Instance() { Assert.Equal( CoreStrings.TranslationFailed( - "(c) => 1 == (Unhandled parameter: __context_0).CustomerOrderCountWithClientInstance(Abs((Unhandled parameter: __context_0).AddOneInstance(c.Id)))"), - Assert.Throws( + "Where( source: DbSet, predicate: (c) => 1 == (Unhandled parameter: __context_0).CustomerOrderCountWithClientInstance(Abs((Unhandled parameter: __context_0).AddOneInstance(c.Id))))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 1 == context.CustomerOrderCountWithClientInstance(Math.Abs(context.AddOneInstance(c.Id))) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -1251,11 +1251,11 @@ public virtual void Scalar_Nested_Function_UDF_Client_BCL_Instance() { Assert.Equal( CoreStrings.TranslationFailed( - "(c) => 1 == (Unhandled parameter: __context_0).CustomerOrderCountWithClientInstance((Unhandled parameter: __context_0).AddOneInstance(Abs(c.Id)))"), - Assert.Throws( + "Where( source: DbSet, predicate: (c) => 1 == (Unhandled parameter: __context_0).CustomerOrderCountWithClientInstance((Unhandled parameter: __context_0).AddOneInstance(Abs(c.Id))))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 1 == context.CustomerOrderCountWithClientInstance(context.AddOneInstance(Math.Abs(c.Id))) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -1266,11 +1266,11 @@ public virtual void Scalar_Nested_Function_Client_BCL_Instance() { Assert.Equal( CoreStrings.TranslationFailed( - "(c) => 3 == (Unhandled parameter: __context_0).AddOneInstance(Abs(c.Id))"), - Assert.Throws( + "Where( source: DbSet, predicate: (c) => 3 == (Unhandled parameter: __context_0).AddOneInstance(Abs(c.Id)))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 3 == context.AddOneInstance(Math.Abs(c.Id)) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -1281,11 +1281,11 @@ public virtual void Scalar_Nested_Function_Client_UDF_Instance() { Assert.Equal( CoreStrings.TranslationFailed( - "(c) => 2 == (Unhandled parameter: __context_0).AddOneInstance((Unhandled parameter: __context_0).CustomerOrderCountWithClientInstance(c.Id))"), - Assert.Throws( + "Where( source: DbSet, predicate: (c) => 2 == (Unhandled parameter: __context_0).AddOneInstance((Unhandled parameter: __context_0).CustomerOrderCountWithClientInstance(c.Id)))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 2 == context.AddOneInstance(context.CustomerOrderCountWithClientInstance(c.Id)) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -1295,11 +1295,11 @@ public virtual void Scalar_Nested_Function_BCL_Client_Instance() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => 3 == Abs((Unhandled parameter: __context_0).AddOneInstance(c.Id))"), - Assert.Throws( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => 3 == Abs((Unhandled parameter: __context_0).AddOneInstance(c.Id)))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 3 == Math.Abs(context.AddOneInstance(c.Id)) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -1331,11 +1331,11 @@ public virtual void Scalar_Nested_Function_UDF_Client_Instance() { Assert.Equal( CoreStrings.TranslationFailed( - "(c) => 2 == (Unhandled parameter: __context_0).CustomerOrderCountWithClientInstance((Unhandled parameter: __context_0).AddOneInstance(c.Id))"), - Assert.Throws( + "Where( source: DbSet, predicate: (c) => 2 == (Unhandled parameter: __context_0).CustomerOrderCountWithClientInstance((Unhandled parameter: __context_0).AddOneInstance(c.Id)))"), + RemoveNewLines(Assert.Throws( () => (from c in context.Customers where 2 == context.CustomerOrderCountWithClientInstance(context.AddOneInstance(c.Id)) - select c.Id).Single()).Message); + select c.Id).Single()).Message)); } } @@ -1355,5 +1355,8 @@ public virtual void Scalar_Nested_Function_UDF_BCL_Instance() #endregion #endregion + + private string RemoveNewLines(string message) + => message.Replace("\n", "").Replace("\r", ""); } } diff --git a/test/EFCore.Specification.Tests/Query/FiltersTestBase.cs b/test/EFCore.Specification.Tests/Query/FiltersTestBase.cs index b4236a1d54b..913d0312519 100644 --- a/test/EFCore.Specification.Tests/Query/FiltersTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/FiltersTestBase.cs @@ -51,9 +51,9 @@ public virtual void Find() public virtual void Client_eval() { Assert.Equal( - CoreStrings.TranslationFailed("(p) => ClientMethod(p)"), - Assert.Throws( - () => _context.Products.ToList()).Message); + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (p) => ClientMethod(p))"), + RemoveNewLines(Assert.Throws( + () => _context.Products.ToList()).Message)); } [ConditionalFact] @@ -135,9 +135,9 @@ public virtual void Project_reference_that_itself_has_query_filter_with_another_ public virtual void Included_one_to_many_query_with_client_eval() { Assert.Equal( - CoreStrings.TranslationFailed("(p) => ClientMethod(p)"), - Assert.Throws( - () => _context.Products.Include(p => p.OrderDetails).ToList()).Message); + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (p) => ClientMethod(p))"), + RemoveNewLines(Assert.Throws( + () => _context.Products.Include(p => p.OrderDetails).ToList()).Message)); } [ConditionalFact(Skip = "issue #15081")] @@ -171,5 +171,8 @@ public virtual void Compiled_query() protected NorthwindContext CreateContext() => Fixture.CreateContext(); public void Dispose() => _context.Dispose(); + + private string RemoveNewLines(string message) + => message.Replace("\n", "").Replace("\r", ""); } } diff --git a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs index 678e8fe27cc..aa116131d95 100644 --- a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs @@ -1328,7 +1328,7 @@ orderby g.Nickname assertOrder: true))).Message; Assert.Equal( - CoreStrings.TranslationFailed("(g) => g.LeaderNickname != null ? new { HasSoulPatch = g.HasSoulPatch } : null == null"), + CoreStrings.TranslationFailed("Where( source: OrderBy( source: DbSet, keySelector: (g) => g.Nickname), predicate: (g) => g.LeaderNickname != null ? new { HasSoulPatch = g.HasSoulPatch } : null == null)"), RemoveNewLines(message)); } @@ -1370,7 +1370,7 @@ public virtual async Task Where_coalesce_with_anonymous_types(bool isAsync) select g.Nickname))).Message; Assert.Equal( - CoreStrings.TranslationFailed("(g) => new { Name = g.LeaderNickname } ?? new { Name = g.FullName } != null"), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (g) => new { Name = g.LeaderNickname } ?? new { Name = g.FullName } != null)"), RemoveNewLines(message)); } @@ -1804,7 +1804,7 @@ public virtual async Task Select_Where_Navigation_Client(bool isAsync) select t))).Message; Assert.Equal( - CoreStrings.TranslationFailed("(c) => Property(c.Inner, \"Nickname\") != null && c.Inner.IsMarcus"), + CoreStrings.TranslationFailed("Where>( source: LeftJoin>( outer: DbSet, inner: DbSet, outerKeySelector: (c) => new AnonymousObject(new object[] { (object)Property(c, \"GearNickName\"), (object)Property>(c, \"GearSquadId\") }), innerKeySelector: (g) => new AnonymousObject(new object[] { (object)Property(g, \"Nickname\"), (object)Property>(g, \"SquadId\") }), resultSelector: (o, i) => new TransparentIdentifier( Outer = o, Inner = i )), predicate: (c) => Property(c.Inner, \"Nickname\") != null && c.Inner.IsMarcus)"), RemoveNewLines(message)); } @@ -3083,7 +3083,7 @@ public virtual async Task Client_side_equality_with_parameter_works_with_optiona elementAsserter: (e, a) => Assert.Equal(e.Nickname, a.Nickname)))).Message; Assert.Equal( - CoreStrings.TranslationFailed("(g) => ClientEquals( first: g.Inner.Note, second: (Unhandled parameter: __prm_0))"), + CoreStrings.TranslationFailed("Where>( source: LeftJoin>( outer: DbSet, inner: DbSet, outerKeySelector: (g) => new AnonymousObject(new object[] { (object)Property(g, \"Nickname\"), (object)Property>(g, \"SquadId\") }), innerKeySelector: (c) => new AnonymousObject(new object[] { (object)Property(c, \"GearNickName\"), (object)Property>(c, \"GearSquadId\") }), resultSelector: (o, i) => new TransparentIdentifier( Outer = o, Inner = i )), predicate: (g) => ClientEquals( first: g.Inner.Note, second: (Unhandled parameter: __prm_0)))"), RemoveNewLines(message)); } @@ -3417,7 +3417,7 @@ public virtual async Task Client_method_on_collection_navigation_in_predicate(bo select g.Nickname))).Message; Assert.Equal( - CoreStrings.TranslationFailed("(g) => g.HasSoulPatch && FavoriteWeapon(MaterializeCollectionNavigation(Navigation: Gear.Weapons (k__BackingField, ICollection) Collection ToDependent Weapon Inverse: Owner, Where( source: DbSet, predicate: (w) => Property(g, \"FullName\") == Property(w, \"OwnerFullName\")))).Name == \"Marcus' Lancer\""), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (g) => g.HasSoulPatch && FavoriteWeapon(MaterializeCollectionNavigation(Navigation: Gear.Weapons (k__BackingField, ICollection) Collection ToDependent Weapon Inverse: Owner, Where( source: DbSet, predicate: (w) => Property(g, \"FullName\") == Property(w, \"OwnerFullName\")))).Name == \"Marcus' Lancer\")"), RemoveNewLines(message)); } @@ -3436,7 +3436,7 @@ public virtual async Task Client_method_on_collection_navigation_in_predicate_ac select g.Nickname))).Message; Assert.Equal( - CoreStrings.TranslationFailed("(g) => !(g.HasSoulPatch) && FavoriteWeapon(MaterializeCollectionNavigation(Navigation: Gear.Weapons (k__BackingField, ICollection) Collection ToDependent Weapon Inverse: Owner, Where( source: DbSet, predicate: (w) => Property(g, \"FullName\") == Property(w, \"OwnerFullName\")))).Name == \"Cole's Gnasher\""), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (g) => !(g.HasSoulPatch) && FavoriteWeapon(MaterializeCollectionNavigation(Navigation: Gear.Weapons (k__BackingField, ICollection) Collection ToDependent Weapon Inverse: Owner, Where( source: DbSet, predicate: (w) => Property(g, \"FullName\") == Property(w, \"OwnerFullName\")))).Name == \"Cole's Gnasher\")"), RemoveNewLines(message)); } @@ -3454,7 +3454,7 @@ orderby FavoriteWeapon(g.Weapons).Name descending assertOrder: true))).Message; Assert.Equal( - CoreStrings.TranslationFailed("(g) => FavoriteWeapon(MaterializeCollectionNavigation(Navigation: Gear.Weapons (k__BackingField, ICollection) Collection ToDependent Weapon Inverse: Owner, Where( source: DbSet, predicate: (w) => Property(g, \"FullName\") == Property(w, \"OwnerFullName\")))).Name"), + CoreStrings.TranslationFailed("OrderByDescending( source: Where( source: DbSet, predicate: (g) => !(g.HasSoulPatch)), keySelector: (g) => FavoriteWeapon(MaterializeCollectionNavigation(Navigation: Gear.Weapons (k__BackingField, ICollection) Collection ToDependent Weapon Inverse: Owner, Where( source: DbSet, predicate: (w) => Property(g, \"FullName\") == Property(w, \"OwnerFullName\")))).Name)"), RemoveNewLines(message)); } @@ -6496,7 +6496,7 @@ public virtual async Task Correlated_collection_order_by_constant_null_of_non_ma }))).Message; Assert.Equal( - CoreStrings.TranslationFailed("(g) => null"), + CoreStrings.TranslationFailed("OrderByDescending( source: DbSet, keySelector: (g) => null)"), RemoveNewLines(message)); } @@ -7213,7 +7213,7 @@ public virtual async Task GetValueOrDefault_on_DateTimeOffset(bool isAsync) ms => ms.Where(m => ((DateTimeOffset?)m.Timeline).GetValueOrDefault() == defaultValue)))).Message; Assert.Equal( - CoreStrings.TranslationFailed("(m) => (Nullable)m.Timeline.GetValueOrDefault() == (Unhandled parameter: __defaultValue_0)"), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (m) => (Nullable)m.Timeline.GetValueOrDefault() == (Unhandled parameter: __defaultValue_0))"), RemoveNewLines(message)); } diff --git a/test/EFCore.Specification.Tests/Query/IncludeAsyncTestBase.cs b/test/EFCore.Specification.Tests/Query/IncludeAsyncTestBase.cs index 134662acf0c..aad6d1b5f73 100644 --- a/test/EFCore.Specification.Tests/Query/IncludeAsyncTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/IncludeAsyncTestBase.cs @@ -715,12 +715,12 @@ public virtual async Task Include_collection_with_client_filter() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon"), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => c.IsLondon)"), (await Assert.ThrowsAsync( () => context.Set() .Include(c => c.Orders) .Where(c => c.IsLondon) - .ToListAsync())).Message); + .ToListAsync())).Message.Replace("\r", "").Replace("\n","")); } } diff --git a/test/EFCore.Specification.Tests/Query/IncludeTestBase.cs b/test/EFCore.Specification.Tests/Query/IncludeTestBase.cs index a9d1f8f5e25..b306ab9f21e 100644 --- a/test/EFCore.Specification.Tests/Query/IncludeTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/IncludeTestBase.cs @@ -1991,7 +1991,7 @@ public virtual void Include_collection_with_client_filter(bool useString) using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon"), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => c.IsLondon)"), Assert.Throws( () => useString ? context.Set() @@ -2001,7 +2001,7 @@ public virtual void Include_collection_with_client_filter(bool useString) : context.Set() .Include(c => c.Orders) .Where(c => c.IsLondon) - .ToList()).Message); + .ToList()).Message.Replace("\r", "").Replace("\n", "")); } } diff --git a/test/EFCore.Specification.Tests/Query/QueryNavigationsTestBase.cs b/test/EFCore.Specification.Tests/Query/QueryNavigationsTestBase.cs index aa267139027..23379258937 100644 --- a/test/EFCore.Specification.Tests/Query/QueryNavigationsTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/QueryNavigationsTestBase.cs @@ -47,7 +47,7 @@ public virtual async Task Join_with_nav_projected_in_subquery_when_client_eval(b { Assert.Equal( CoreStrings.TranslationFailed( - "(c) => c.CustomerID; (o) => ClientProjection( t: o.Outer, _: o.Inner).CustomerID; (c, o) => new TransparentIdentifier>( Outer = c, Inner = o)"), + "Join, string, TransparentIdentifier>>( outer: DbSet, inner: LeftJoin>( outer: DbSet, inner: DbSet, outerKeySelector: (o) => Property(o, \"CustomerID\"), innerKeySelector: (c0) => Property(c0, \"CustomerID\"), resultSelector: (o, i) => new TransparentIdentifier( Outer = o, Inner = i )), outerKeySelector: (c) => c.CustomerID, innerKeySelector: (o) => ClientProjection( t: o.Outer, _: o.Inner).CustomerID, resultSelector: (c, o) => new TransparentIdentifier>( Outer = c, Inner = o ))"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( @@ -81,7 +81,7 @@ from od in grouping2 public virtual async Task Join_with_nav_in_predicate_in_subquery_when_client_eval(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(o) => ClientPredicate( t: o.Outer, _: o.Inner)"), + CoreStrings.TranslationFailed("Where>( source: LeftJoin>( outer: DbSet, inner: DbSet, outerKeySelector: (o) => Property(o, \"CustomerID\"), innerKeySelector: (c0) => Property(c0, \"CustomerID\"), resultSelector: (o, i) => new TransparentIdentifier( Outer = o, Inner = i )), predicate: (o) => ClientPredicate( t: o.Outer, _: o.Inner))"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( @@ -113,7 +113,7 @@ from od in grouping2 public virtual async Task Join_with_nav_in_orderby_in_subquery_when_client_eval(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(o) => ClientOrderBy( t: o.Outer, _: o.Inner)"), + CoreStrings.TranslationFailed("OrderBy, int>( source: LeftJoin>( outer: DbSet, inner: DbSet, outerKeySelector: (o) => Property(o, \"CustomerID\"), innerKeySelector: (c0) => Property(c0, \"CustomerID\"), resultSelector: (o, i) => new TransparentIdentifier( Outer = o, Inner = i )), keySelector: (o) => ClientOrderBy( t: o.Outer, _: o.Inner))"), RemoveNewLines((await Assert.ThrowsAsync( () => AssertQuery( isAsync, @@ -226,7 +226,7 @@ public virtual async Task Select_Where_Navigation_Client(bool isAsync) { Assert.Equal( CoreStrings.TranslationFailed( - "(o) => o.Inner.IsLondon"), + "Where>( source: LeftJoin>( outer: DbSet, inner: DbSet, outerKeySelector: (o) => Property(o, \"CustomerID\"), innerKeySelector: (c) => Property(c, \"CustomerID\"), resultSelector: (o, i) => new TransparentIdentifier( Outer = o, Inner = i )), predicate: (o) => o.Inner.IsLondon)"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( @@ -741,8 +741,8 @@ public virtual Task Collection_select_nav_prop_all(bool isAsync) public virtual async Task Collection_select_nav_prop_all_client(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(o0) => o0.ShipCity == \"London\""), - (await Assert.ThrowsAsync( + CoreStrings.TranslationFailed("All( source: Where( source: DbSet, predicate: (o0) => Property(EntityShaperExpression: EntityType: Customer ValueBufferExpression: ProjectionBindingExpression: EmptyProjectionMember IsNullable: False , \"CustomerID\") == Property(o0, \"CustomerID\")), predicate: (o0) => o0.ShipCity == \"London\")"), + RemoveNewLines((await Assert.ThrowsAsync( () => AssertQuery( isAsync, cs => from c in cs @@ -757,7 +757,7 @@ orderby c.CustomerID { All = (c.Orders ?? new List()).All(o => false) }, - assertOrder: true))).Message); + assertOrder: true))).Message)); } [ConditionalTheory] @@ -782,7 +782,7 @@ public virtual void Collection_where_nav_prop_all_client() { Assert.Equal( CoreStrings.TranslationFailed( - "(o) => o.ShipCity == \"London\""), + "All( source: Where( source: DbSet, predicate: (o) => Property(EntityShaperExpression: EntityType: Customer ValueBufferExpression: ProjectionBindingExpression: EmptyProjectionMember IsNullable: False , \"CustomerID\") == Property(o, \"CustomerID\")), predicate: (o) => o.ShipCity == \"London\")"), RemoveNewLines( Assert.Throws( () => (from c in context.Set() @@ -1149,7 +1149,7 @@ public virtual async Task Where_subquery_on_navigation_client_eval(bool isAsync) { Assert.Equal( CoreStrings.TranslationFailed( - "(o) => ClientMethod(o.OrderID)"), + "OrderByDescending( source: DbSet, keySelector: (o) => ClientMethod(o.OrderID))"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( diff --git a/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.ResultOperators.cs b/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.ResultOperators.cs index 340ba8c7c0b..edd13292fde 100644 --- a/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.ResultOperators.cs +++ b/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.ResultOperators.cs @@ -696,7 +696,7 @@ public virtual async Task Where_OrderBy_Count_client_eval(bool isAsync) { Assert.Equal( CoreStrings.TranslationFailed( - "(o) => ClientEvalPredicate(o)"), + "Where( source: DbSet, predicate: (o) => ClientEvalPredicate(o))"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertCount( @@ -719,7 +719,7 @@ public virtual async Task OrderBy_Where_Count_client_eval(bool isAsync) { Assert.Equal( CoreStrings.TranslationFailed( - "(o) => ClientEvalPredicate(o)"), + "Where( source: OrderBy( source: DbSet, keySelector: (o) => 42), predicate: (o) => ClientEvalPredicate(o))"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertCount( @@ -733,7 +733,7 @@ public virtual async Task OrderBy_Where_Count_client_eval_mixed(bool isAsync) { Assert.Equal( CoreStrings.TranslationFailed( - "(o) => ClientEvalPredicate(o)"), + "Where( source: OrderBy( source: DbSet, keySelector: (o) => o.OrderID), predicate: (o) => ClientEvalPredicate(o))"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertCount( @@ -747,7 +747,7 @@ public virtual async Task OrderBy_Count_with_predicate_client_eval(bool isAsync) { Assert.Equal( CoreStrings.TranslationFailed( - "(o) => ClientEvalPredicate(o)"), + "Count( source: OrderBy( source: DbSet, keySelector: (o) => 42), predicate: (o) => ClientEvalPredicate(o))"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertCount( @@ -762,7 +762,7 @@ public virtual async Task OrderBy_Count_with_predicate_client_eval_mixed(bool is { Assert.Equal( CoreStrings.TranslationFailed( - "(o) => ClientEvalPredicate(o)"), + "Count( source: OrderBy( source: DbSet, keySelector: (o) => o.OrderID), predicate: (o) => ClientEvalPredicate(o))"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertCount( @@ -777,7 +777,7 @@ public virtual async Task OrderBy_Where_Count_with_predicate_client_eval(bool is { Assert.Equal( CoreStrings.TranslationFailed( - "(o) => ClientEvalPredicate(o)"), + "Where( source: OrderBy( source: DbSet, keySelector: (o) => 42), predicate: (o) => ClientEvalPredicate(o))"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertCount( @@ -792,7 +792,7 @@ public virtual async Task OrderBy_Where_Count_with_predicate_client_eval_mixed(b { Assert.Equal( CoreStrings.TranslationFailed( - "(o) => ClientEvalPredicate(o)"), + "Where( source: OrderBy( source: DbSet, keySelector: (o) => o.OrderID), predicate: (o) => ClientEvalPredicate(o))"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertCount( @@ -1459,7 +1459,7 @@ public virtual async Task Contains_with_local_tuple_array_closure(bool isAsync) Assert.Equal( CoreStrings.TranslationFailed( - "(o) => Contains>( source: (Unhandled parameter: __ids_0), value: new Tuple( o.OrderID, o.ProductID ))"), + "Where( source: DbSet, predicate: (o) => Contains>( source: (Unhandled parameter: __ids_0), value: new Tuple( o.OrderID, o.ProductID )))"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( diff --git a/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.Select.cs b/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.Select.cs index 0ae165e37ea..19bd4c35d04 100644 --- a/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.Select.cs +++ b/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.Select.cs @@ -136,7 +136,7 @@ public virtual async Task Select_bool_closure_with_order_by_property_with_cast_t var boolean = false; Assert.Equal( - CoreStrings.TranslationFailed("(c) => (Nullable)(Unhandled parameter: __p_0).f"), + CoreStrings.TranslationFailed("OrderBy>( source: DbSet, keySelector: (c) => (Nullable)(Unhandled parameter: __p_0).f)"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( diff --git a/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.Where.cs b/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.Where.cs index 972c9602519..27f6aaae05f 100644 --- a/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.Where.cs +++ b/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.Where.cs @@ -638,7 +638,7 @@ where EF.Property(e, "Title") public virtual async Task Where_client(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon"), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => c.IsLondon)"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( @@ -662,7 +662,7 @@ public virtual Task Where_subquery_correlated(bool isAsync) public virtual async Task Where_subquery_correlated_client_eval(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(c0) => EntityShaperExpression: EntityType: Customer ValueBufferExpression: ProjectionBindingExpression: EmptyProjectionMember IsNullable: False.CustomerID == c0.CustomerID && c0.IsLondon"), + CoreStrings.TranslationFailed("Any( source: DbSet, predicate: (c0) => EntityShaperExpression: EntityType: Customer ValueBufferExpression: ProjectionBindingExpression: EmptyProjectionMember IsNullable: False .CustomerID == c0.CustomerID && c0.IsLondon)"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( @@ -677,7 +677,7 @@ public virtual async Task Where_subquery_correlated_client_eval(bool isAsync) public virtual async Task Where_client_and_server_top_level(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon && c.CustomerID != \"AROUT\""), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => c.IsLondon && c.CustomerID != \"AROUT\")"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( @@ -691,7 +691,7 @@ public virtual async Task Where_client_and_server_top_level(bool isAsync) public virtual async Task Where_client_or_server_top_level(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon || c.CustomerID == \"ALFKI\""), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => c.IsLondon || c.CustomerID == \"ALFKI\")"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( @@ -705,7 +705,7 @@ public virtual async Task Where_client_or_server_top_level(bool isAsync) public virtual async Task Where_client_and_server_non_top_level(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.CustomerID != \"ALFKI\" == c.IsLondon && c.CustomerID != \"AROUT\""), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => c.CustomerID != \"ALFKI\" == c.IsLondon && c.CustomerID != \"AROUT\")"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( @@ -719,7 +719,7 @@ public virtual async Task Where_client_and_server_non_top_level(bool isAsync) public virtual async Task Where_client_deep_inside_predicate_and_server_top_level(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.CustomerID != \"ALFKI\" && c.CustomerID == \"MAUMAR\" || c.CustomerID != \"AROUT\" && c.IsLondon"), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => c.CustomerID != \"ALFKI\" && c.CustomerID == \"MAUMAR\" || c.CustomerID != \"AROUT\" && c.IsLondon)"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( @@ -1331,7 +1331,7 @@ public virtual Task Where_bool_member_false(bool isAsync) public virtual async Task Where_bool_client_side_negated(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(p) => !(ClientFunc(p.ProductID)) && p.Discontinued"), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (p) => !(ClientFunc(p.ProductID)) && p.Discontinued)"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( diff --git a/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.cs index c40e717e2c0..0bab39a3534 100644 --- a/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.cs @@ -675,7 +675,7 @@ public virtual Task Queryable_simple_anonymous_subquery(bool isAsync) public virtual async Task Queryable_reprojection(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon"), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => c.IsLondon)"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( @@ -1235,7 +1235,7 @@ public virtual Task All_top_level_subquery_ef_property(bool isAsync) public virtual async Task All_client(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon"), + CoreStrings.TranslationFailed("All( source: DbSet, predicate: (c) => c.IsLondon)"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertAll( @@ -1249,7 +1249,7 @@ public virtual async Task All_client(bool isAsync) public virtual async Task All_client_and_server_top_level(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.CustomerID != \"Foo\" && c.IsLondon"), + CoreStrings.TranslationFailed("All( source: DbSet, predicate: (c) => c.CustomerID != \"Foo\" && c.IsLondon)"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertAll( @@ -1263,7 +1263,7 @@ public virtual async Task All_client_and_server_top_level(bool isAsync) public virtual async Task All_client_or_server_top_level(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.CustomerID != \"Foo\" || c.IsLondon"), + CoreStrings.TranslationFailed("All( source: DbSet, predicate: (c) => c.CustomerID != \"Foo\" || c.IsLondon)"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertAll( @@ -1393,7 +1393,7 @@ public virtual Task Cast_results_to_object(bool isAsync) public virtual async Task First_client_predicate(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon"), + CoreStrings.TranslationFailed("Where( source: OrderBy( source: DbSet, keySelector: (c) => c.CustomerID), predicate: (c) => c.IsLondon)"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertFirst( @@ -2267,7 +2267,7 @@ where e1.FirstName public virtual async Task Where_query_composition3(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(c0) => c0.IsLondon"), + CoreStrings.TranslationFailed("Where( source: OrderBy( source: DbSet, keySelector: (c0) => c0.CustomerID), predicate: (c0) => c0.IsLondon)"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( @@ -2284,7 +2284,7 @@ from c1 in cs public virtual async Task Where_query_composition4(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(c1) => c1.IsLondon"), + CoreStrings.TranslationFailed("OrderBy( source: DbSet, keySelector: (c1) => c1.IsLondon)"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( @@ -2307,7 +2307,7 @@ public virtual async Task Where_query_composition5(bool isAsync) { Assert.Equal( CoreStrings.TranslationFailed( - "(c) => c.IsLondon == First(Select( source: OrderBy( source: DbSet, keySelector: (c0) => c0.CustomerID), selector: (c0) => c0.IsLondon))"), + "Where( source: DbSet, predicate: (c) => c.IsLondon == First(Select( source: OrderBy( source: DbSet, keySelector: (c0) => c0.CustomerID), selector: (c0) => c0.IsLondon)))"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( @@ -2324,7 +2324,7 @@ from c1 in cs public virtual async Task Where_query_composition6(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon == First(Select( source: OrderBy( source: DbSet, keySelector: (c0) => c0.CustomerID), selector: (c0) => c0.IsLondon))"), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (c) => c.IsLondon == First(Select( source: OrderBy( source: DbSet, keySelector: (c0) => c0.CustomerID), selector: (c0) => c0.IsLondon)))"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( @@ -3081,7 +3081,7 @@ public virtual Task OrderBy_anon2(bool isAsync) public virtual async Task OrderBy_client_mixed(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => c.IsLondon"), + CoreStrings.TranslationFailed("OrderBy( source: DbSet, keySelector: (c) => c.IsLondon)"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( @@ -3096,7 +3096,7 @@ public virtual async Task OrderBy_client_mixed(bool isAsync) public virtual async Task OrderBy_multiple_queries(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => new Foo{ Bar = c.CustomerID }; (o) => new Foo{ Bar = o.CustomerID }; (c, o) => new TransparentIdentifier( Outer = c, Inner = o)"), + CoreStrings.TranslationFailed("Join>( outer: DbSet, inner: DbSet, outerKeySelector: (c) => new Foo{ Bar = c.CustomerID } , innerKeySelector: (o) => new Foo{ Bar = o.CustomerID } , resultSelector: (c, o) => new TransparentIdentifier( Outer = c, Inner = o ))"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQuery( @@ -4011,7 +4011,7 @@ public virtual void Random_next_is_not_funcletized_1() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(o) => o.OrderID > new Random().Next()"), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (o) => o.OrderID > new Random().Next())"), RemoveNewLines( Assert.Throws( () => context.Orders @@ -4026,7 +4026,7 @@ public virtual void Random_next_is_not_funcletized_2() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(o) => o.OrderID > new Random().Next(5)"), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (o) => o.OrderID > new Random().Next(5))"), RemoveNewLines( Assert.Throws( () => context.Orders @@ -4041,7 +4041,7 @@ public virtual void Random_next_is_not_funcletized_3() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(o) => o.OrderID > new Random().Next( minValue: 0, maxValue: 10)"), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (o) => o.OrderID > new Random().Next( minValue: 0, maxValue: 10))"), RemoveNewLines( Assert.Throws( () => context.Orders @@ -4056,7 +4056,7 @@ public virtual void Random_next_is_not_funcletized_4() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(o) => o.OrderID > new Random(15).Next()"), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (o) => o.OrderID > new Random(15).Next())"), RemoveNewLines( Assert.Throws( () => context.Orders @@ -4071,7 +4071,7 @@ public virtual void Random_next_is_not_funcletized_5() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(o) => o.OrderID > new Random(15).Next(5)"), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (o) => o.OrderID > new Random(15).Next(5))"), RemoveNewLines( Assert.Throws( () => context.Orders @@ -4086,7 +4086,7 @@ public virtual void Random_next_is_not_funcletized_6() using (var context = CreateContext()) { Assert.Equal( - CoreStrings.TranslationFailed("(o) => o.OrderID > new Random(15).Next( minValue: 0, maxValue: 10)"), + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (o) => o.OrderID > new Random(15).Next( minValue: 0, maxValue: 10))"), RemoveNewLines( Assert.Throws( () => context.Orders @@ -6097,7 +6097,7 @@ public virtual Task Let_entity_equality_to_other_entity(bool isAsync) public virtual async Task SelectMany_after_client_method(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(c) => ClientOrderBy(c)"), + CoreStrings.TranslationFailed("OrderBy( source: DbSet, keySelector: (c) => ClientOrderBy(c))"), RemoveNewLines( (await Assert.ThrowsAsync( () => AssertQueryScalar( diff --git a/test/EFCore.Sqlite.FunctionalTests/BuiltInDataTypesSqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/BuiltInDataTypesSqliteTest.cs index 8490a172e1a..72b1dff0283 100644 --- a/test/EFCore.Sqlite.FunctionalTests/BuiltInDataTypesSqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/BuiltInDataTypesSqliteTest.cs @@ -1129,7 +1129,7 @@ public virtual void Cant_query_Average_of_converted_types() .Average(e => e.TestNullableDecimal)); Assert.Equal( CoreStrings.TranslationFailed( - "Projection Mapping: EmptyProjectionMember -> [EntityProjectionExpression]SELECT 1FROM BuiltInNullableDataTypes AS bWHERE b.PartitionId == 202"), + "Average( source: Where( source: DbSet, predicate: (b) => b.PartitionId == 202), selector: (b) => b.TestNullableDecimal)"), RemoveNewLines(ex.Message)); } } @@ -1162,7 +1162,8 @@ public virtual void Cant_query_Sum_of_converted_types() .Where(e => e.PartitionId == 203) .Sum(e => e.TestDecimal)); Assert.Equal( - CoreStrings.TranslationFailed("Projection Mapping: EmptyProjectionMember -> [EntityProjectionExpression]SELECT 1FROM BuiltInDataTypes AS bWHERE b.PartitionId == 203"), + CoreStrings.TranslationFailed( + "Sum( source: Where( source: DbSet, predicate: (b) => b.PartitionId == 203), selector: (b) => b.TestDecimal)"), RemoveNewLines(ex.Message)); } } diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/GearsOfWarQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/GearsOfWarQuerySqliteTest.cs index 515ca679368..c4b97302749 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/GearsOfWarQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/GearsOfWarQuerySqliteTest.cs @@ -19,110 +19,110 @@ public GearsOfWarQuerySqliteTest(GearsOfWarQuerySqliteFixture fixture) public override async Task Where_datetimeoffset_date_component(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(m) => m.Timeline.Date > (Unhandled parameter: __Date_0)"), - (await Assert.ThrowsAsync( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (m) => m.Timeline.Date > (Unhandled parameter: __Date_0))"), + RemoveNewLines((await Assert.ThrowsAsync( () => base.Where_datetimeoffset_date_component(isAsync))) - .Message); + .Message)); } // SQLite client-eval public override async Task Where_datetimeoffset_day_component(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(m) => m.Timeline.Day == 2"), - (await Assert.ThrowsAsync( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (m) => m.Timeline.Day == 2)"), + RemoveNewLines((await Assert.ThrowsAsync( () => base.Where_datetimeoffset_day_component(isAsync))) - .Message); + .Message)); } // SQLite client-eval public override async Task Where_datetimeoffset_dayofyear_component(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(m) => m.Timeline.DayOfYear == 2"), - (await Assert.ThrowsAsync( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (m) => m.Timeline.DayOfYear == 2)"), + RemoveNewLines((await Assert.ThrowsAsync( () => base.Where_datetimeoffset_dayofyear_component(isAsync))) - .Message); + .Message)); } // SQLite client-eval public override async Task Where_datetimeoffset_hour_component(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(m) => m.Timeline.Hour == 10"), - (await Assert.ThrowsAsync( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (m) => m.Timeline.Hour == 10)"), + RemoveNewLines((await Assert.ThrowsAsync( () => base.Where_datetimeoffset_hour_component(isAsync))) - .Message); + .Message)); } // SQLite client-eval public override async Task Where_datetimeoffset_millisecond_component(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(m) => m.Timeline.Millisecond == 0"), - (await Assert.ThrowsAsync( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (m) => m.Timeline.Millisecond == 0)"), + RemoveNewLines((await Assert.ThrowsAsync( () => base.Where_datetimeoffset_millisecond_component(isAsync))) - .Message); + .Message)); } // SQLite client-eval public override async Task Where_datetimeoffset_minute_component(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(m) => m.Timeline.Minute == 0"), - (await Assert.ThrowsAsync( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (m) => m.Timeline.Minute == 0)"), + RemoveNewLines((await Assert.ThrowsAsync( () => base.Where_datetimeoffset_minute_component(isAsync))) - .Message); + .Message)); } // SQLite client-eval public override async Task Where_datetimeoffset_month_component(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(m) => m.Timeline.Month == 1"), - (await Assert.ThrowsAsync( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (m) => m.Timeline.Month == 1)"), + RemoveNewLines((await Assert.ThrowsAsync( () => base.Where_datetimeoffset_month_component(isAsync))) - .Message); + .Message)); } // SQLite client-eval public override async Task Where_datetimeoffset_now(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(m) => m.Timeline != DateTimeOffset.Now"), - (await Assert.ThrowsAsync( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (m) => m.Timeline != DateTimeOffset.Now)"), + RemoveNewLines((await Assert.ThrowsAsync( () => base.Where_datetimeoffset_now(isAsync))) - .Message); + .Message)); } // SQLite client-eval public override async Task Where_datetimeoffset_second_component(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(m) => m.Timeline.Second == 0"), - (await Assert.ThrowsAsync( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (m) => m.Timeline.Second == 0)"), + RemoveNewLines((await Assert.ThrowsAsync( () => base.Where_datetimeoffset_second_component(isAsync))) - .Message); + .Message)); } // SQLite client-eval public override async Task Where_datetimeoffset_utcnow(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(m) => m.Timeline != DateTimeOffset.UtcNow"), - (await Assert.ThrowsAsync( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (m) => m.Timeline != DateTimeOffset.UtcNow)"), + RemoveNewLines((await Assert.ThrowsAsync( () => base.Where_datetimeoffset_utcnow(isAsync))) - .Message); + .Message)); } // SQLite client-eval public override async Task Where_datetimeoffset_year_component(bool isAsync) { Assert.Equal( - CoreStrings.TranslationFailed("(m) => m.Timeline.Year == 2"), - (await Assert.ThrowsAsync( + CoreStrings.TranslationFailed("Where( source: DbSet, predicate: (m) => m.Timeline.Year == 2)"), + RemoveNewLines((await Assert.ThrowsAsync( () => base.Where_datetimeoffset_year_component(isAsync))) - .Message); + .Message)); } // SQLite client-eval @@ -130,7 +130,7 @@ public override async Task DateTimeOffset_Contains_Less_than_Greater_than(bool i { Assert.Equal( CoreStrings.TranslationFailed( - "(m) => (Unhandled parameter: __start_0) <= (DateTimeOffset)m.Timeline.Date && m.Timeline < (Unhandled parameter: __end_1) && Contains( source: (Unhandled parameter: __dates_2), value: m.Timeline)"), + "Where( source: DbSet, predicate: (m) => (Unhandled parameter: __start_0) <= (DateTimeOffset)m.Timeline.Date && m.Timeline < (Unhandled parameter: __end_1) && Contains( source: (Unhandled parameter: __dates_2), value: m.Timeline))"), RemoveNewLines( (await Assert.ThrowsAsync( () => base.DateTimeOffset_Contains_Less_than_Greater_than(isAsync)))