From a373d48eb0b589decab62576d0f5a0e7bbf0a169 Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Mon, 17 Aug 2020 14:45:59 -0700 Subject: [PATCH] Move exception messages Resolves #16712 --- .../Properties/CosmosStrings.Designer.cs | 28 +++++++ .../Properties/CosmosStrings.resx | 12 +++ ...yableMethodTranslatingExpressionVisitor.cs | 2 +- .../CosmosSqlTranslatingExpressionVisitor.cs | 3 +- .../Internal/EntityProjectionExpression.cs | 6 +- .../Query/Internal/SqlBinaryExpression.cs | 5 +- .../Query/Internal/SqlExpression.cs | 3 +- .../Query/Internal/SqlExpressionFactory.cs | 7 +- .../Query/Internal/SqlUnaryExpression.cs | 5 +- .../Properties/InMemoryStrings.Designer.cs | 8 ++ .../Properties/InMemoryStrings.resx | 3 + .../Internal/EntityProjectionExpression.cs | 9 +-- .../Properties/RelationalStrings.Designer.cs | 36 +++++++++ .../Properties/RelationalStrings.resx | 15 ++++ .../Query/EntityProjectionExpression.cs | 18 +---- ...yableMethodTranslatingExpressionVisitor.cs | 4 +- ...lationalSqlTranslatingExpressionVisitor.cs | 2 +- .../Query/SqlExpressionFactory.cs | 6 +- .../SqlExpressions/SqlBinaryExpression.cs | 4 +- .../Query/SqlExpressions/SqlExpression.cs | 2 +- .../SqlExpressions/SqlUnaryExpression.cs | 4 +- src/EFCore/Properties/CoreStrings.Designer.cs | 79 +------------------ src/EFCore/Properties/CoreStrings.resx | 38 +-------- .../NavigationExpandingExpressionVisitor.cs | 2 + ...windAggregateOperatorsQueryInMemoryTest.cs | 12 --- ...hwindIncludeNoTrackingQueryInMemoryTest.cs | 8 -- .../NorthwindIncludeQueryInMemoryTest.cs | 8 -- ...NorthwindStringIncludeQueryInMemoryTest.cs | 8 -- ...gregateOperatorsQueryRelationalTestBase.cs | 19 +++++ ...NorthwindIncludeQueryRelationalTestBase.cs | 13 +++ ...windSplitIncludeNoTrackingQueryTestBase.cs | 11 +-- .../NorthwindSplitIncludeQueryTestBase.cs | 11 +-- ...orthwindAggregateOperatorsQueryTestBase.cs | 26 +++--- .../Query/NorthwindIncludeQueryTestBase.cs | 13 ++- ...windIncludeNoTrackingQuerySqlServerTest.cs | 13 +++ ...plitIncludeNoTrackingQuerySqlServerTest.cs | 15 ---- ...NorthwindSplitIncludeQuerySqlServerTest.cs | 12 --- ...orthwindStringIncludeQuerySqlServerTest.cs | 13 +++ ...rthwindIncludeNoTrackingQuerySqliteTest.cs | 10 +++ ...ndSplitIncludeNoTrackingQuerySqliteTest.cs | 12 --- .../NorthwindSplitIncludeQuerySqliteTest.cs | 12 --- .../NorthwindStringIncludeQuerySqliteTest.cs | 10 +++ 42 files changed, 249 insertions(+), 278 deletions(-) diff --git a/src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs b/src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs index d882286cbc7..1959e15273b 100644 --- a/src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs +++ b/src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs @@ -234,6 +234,34 @@ public static string InvalidDerivedTypeInEntityProjection([CanBeNull] object der public static string MissingOrderingInSqlExpression => GetString("MissingOrderingInSqlExpression"); + /// + /// Null TypeMapping in Sql Tree. + /// + public static string NullTypeMappingInSqlTree + => GetString("NullTypeMappingInSqlTree"); + + /// + /// Unable to bind '{memberType}' '{member}' to entity projection of '{entityType}'. + /// + public static string UnableToBindMemberToEntityProjection([CanBeNull] object memberType, [CanBeNull] object member, [CanBeNull] object entityType) + => string.Format( + GetString("UnableToBindMemberToEntityProjection", nameof(memberType), nameof(member), nameof(entityType)), + memberType, member, entityType); + + /// + /// Unsupported operator '{nodeType}' specified for expression of type '{expressionType}'. + /// + public static string UnsupportedOperatorForSqlExpression([CanBeNull] object nodeType, [CanBeNull] object expressionType) + => string.Format( + GetString("UnsupportedOperatorForSqlExpression", nameof(nodeType), nameof(expressionType)), + nodeType, expressionType); + + /// + /// VisitChildren must be overridden in class deriving from SqlExpression. + /// + public static string VisitChildrenMustBeOverridden + => GetString("VisitChildrenMustBeOverridden"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/src/EFCore.Cosmos/Properties/CosmosStrings.resx b/src/EFCore.Cosmos/Properties/CosmosStrings.resx index f5ad2aa8329..427c8a2c9f9 100644 --- a/src/EFCore.Cosmos/Properties/CosmosStrings.resx +++ b/src/EFCore.Cosmos/Properties/CosmosStrings.resx @@ -204,4 +204,16 @@ Reverse could not be translated to the server because there is no ordering on the server side. + + Null TypeMapping in Sql Tree. + + + Unable to bind '{memberType}' '{member}' to entity projection of '{entityType}'. + + + Unsupported operator '{nodeType}' specified for expression of type '{expressionType}'. + + + VisitChildren must be overridden in class deriving from SqlExpression. + \ No newline at end of file diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs index 4713231a8cc..91cdbf66b9d 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs @@ -1214,7 +1214,7 @@ private ShapedQueryExpression AggregateResultShaper( Expression.New( typeof(InvalidOperationException).GetConstructors() .Single(ci => ci.GetParameters().Length == 1), - Expression.Constant(CoreStrings.NoElements)), + Expression.Constant(CoreStrings.SequenceContainsNoElements)), resultType); shaper = Expression.Block( diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs index b45f697199d..c07cd4e2e7e 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs @@ -9,6 +9,7 @@ using System.Linq.Expressions; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Cosmos.Internal; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Internal; @@ -963,7 +964,7 @@ protected override Expression VisitExtension(Expression extensionExpression) if (extensionExpression is SqlExpression sqlExpression && sqlExpression.TypeMapping == null) { - throw new InvalidOperationException(CoreStrings.NullTypeMappingInSqlTree); + throw new InvalidOperationException(CosmosStrings.NullTypeMappingInSqlTree); } return base.VisitExtension(extensionExpression); diff --git a/src/EFCore.Cosmos/Query/Internal/EntityProjectionExpression.cs b/src/EFCore.Cosmos/Query/Internal/EntityProjectionExpression.cs index 70cbf2d1dd8..fd7c02e182d 100644 --- a/src/EFCore.Cosmos/Query/Internal/EntityProjectionExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/EntityProjectionExpression.cs @@ -118,8 +118,7 @@ public virtual Expression BindProperty([NotNull] IProperty property, bool client && !property.DeclaringEntityType.IsAssignableFrom(EntityType)) { throw new InvalidOperationException( - CoreStrings.EntityProjectionExpressionCalledWithIncorrectInterface( - "GetProperty", nameof(IProperty), EntityType.DisplayName(), $"Property:{property.Name}")); + CosmosStrings.UnableToBindMemberToEntityProjection("Property", property.Name, EntityType.DisplayName())); } if (!_propertyExpressionsMap.TryGetValue(property, out var expression)) @@ -150,8 +149,7 @@ public virtual Expression BindNavigation([NotNull] INavigation navigation, bool && !navigation.DeclaringEntityType.IsAssignableFrom(EntityType)) { throw new InvalidOperationException( - CoreStrings.EntityProjectionExpressionCalledWithIncorrectInterface( - "GetNavigation", nameof(INavigation), EntityType.DisplayName(), $"Navigation:{navigation.Name}")); + CosmosStrings.UnableToBindMemberToEntityProjection("Navigation", navigation.Name, EntityType.DisplayName())); } if (!_navigationExpressionsMap.TryGetValue(navigation, out var expression)) diff --git a/src/EFCore.Cosmos/Query/Internal/SqlBinaryExpression.cs b/src/EFCore.Cosmos/Query/Internal/SqlBinaryExpression.cs index 5234803fe42..34e9f16c7bb 100644 --- a/src/EFCore.Cosmos/Query/Internal/SqlBinaryExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/SqlBinaryExpression.cs @@ -5,7 +5,9 @@ using System.Collections.Generic; using System.Linq.Expressions; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Cosmos.Internal; using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; @@ -45,7 +47,8 @@ public class SqlBinaryExpression : SqlExpression private static ExpressionType VerifyOperator(ExpressionType operatorType) => _allowedOperators.Contains(operatorType) ? operatorType - : throw new InvalidOperationException(CoreStrings.UnsupportedBinaryOperator); + : throw new InvalidOperationException(CosmosStrings.UnsupportedOperatorForSqlExpression( + operatorType, typeof(SqlBinaryExpression).ShortDisplayName())); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Cosmos/Query/Internal/SqlExpression.cs b/src/EFCore.Cosmos/Query/Internal/SqlExpression.cs index 9bb3069ac23..dd5da5b8c72 100644 --- a/src/EFCore.Cosmos/Query/Internal/SqlExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/SqlExpression.cs @@ -4,6 +4,7 @@ using System; using System.Linq.Expressions; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Cosmos.Internal; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Storage; @@ -53,7 +54,7 @@ protected SqlExpression([NotNull] Type type, [CanBeNull] CoreTypeMapping typeMap /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected override Expression VisitChildren(ExpressionVisitor visitor) - => throw new InvalidOperationException(CoreStrings.VisitChildrenMustBeOverridden); + => throw new InvalidOperationException(CosmosStrings.VisitChildrenMustBeOverridden); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Cosmos/Query/Internal/SqlExpressionFactory.cs b/src/EFCore.Cosmos/Query/Internal/SqlExpressionFactory.cs index 61f8913a44e..d8b291430af 100644 --- a/src/EFCore.Cosmos/Query/Internal/SqlExpressionFactory.cs +++ b/src/EFCore.Cosmos/Query/Internal/SqlExpressionFactory.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Linq.Expressions; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Cosmos.Internal; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Internal; @@ -137,7 +138,8 @@ when sqlUnaryExpression.IsLogicalNot(): break; default: - throw new InvalidOperationException(CoreStrings.TranslationFailed(sqlUnaryExpression.Print())); + throw new InvalidOperationException(CosmosStrings.UnsupportedOperatorForSqlExpression( + sqlUnaryExpression.OperatorType, typeof(SqlUnaryExpression).ShortDisplayName()));; } return new SqlUnaryExpression(sqlUnaryExpression.OperatorType, operand, resultType, resultTypeMapping); @@ -197,7 +199,8 @@ private SqlExpression ApplyTypeMappingOnSqlBinary( break; default: - throw new InvalidOperationException(CoreStrings.IncorrectOperatorType); + throw new InvalidOperationException(CosmosStrings.UnsupportedOperatorForSqlExpression( + sqlBinaryExpression.OperatorType, typeof(SqlBinaryExpression).ShortDisplayName())); } return new SqlBinaryExpression( diff --git a/src/EFCore.Cosmos/Query/Internal/SqlUnaryExpression.cs b/src/EFCore.Cosmos/Query/Internal/SqlUnaryExpression.cs index 63485f6e568..86ceb83c5ad 100644 --- a/src/EFCore.Cosmos/Query/Internal/SqlUnaryExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/SqlUnaryExpression.cs @@ -5,7 +5,9 @@ using System.Collections.Generic; using System.Linq.Expressions; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Cosmos.Internal; using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; @@ -28,7 +30,8 @@ public class SqlUnaryExpression : SqlExpression private static ExpressionType VerifyOperator(ExpressionType operatorType) => _allowedOperators.Contains(operatorType) ? operatorType - : throw new InvalidOperationException(CoreStrings.UnsupportedUnary); + : throw new InvalidOperationException(CosmosStrings.UnsupportedOperatorForSqlExpression( + operatorType, typeof(SqlUnaryExpression).ShortDisplayName())); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.InMemory/Properties/InMemoryStrings.Designer.cs b/src/EFCore.InMemory/Properties/InMemoryStrings.Designer.cs index 475eba63eda..a1776c47b2b 100644 --- a/src/EFCore.InMemory/Properties/InMemoryStrings.Designer.cs +++ b/src/EFCore.InMemory/Properties/InMemoryStrings.Designer.cs @@ -71,6 +71,14 @@ public static string InvalidDerivedTypeInEntityProjection([CanBeNull] object der GetString("InvalidDerivedTypeInEntityProjection", nameof(derivedType), nameof(entityType)), derivedType, entityType); + /// + /// Unable to bind '{memberType}' '{member}' to entity projection of '{entityType}'. + /// + public static string UnableToBindMemberToEntityProjection([CanBeNull] object memberType, [CanBeNull] object member, [CanBeNull] object entityType) + => string.Format( + GetString("UnableToBindMemberToEntityProjection", nameof(memberType), nameof(member), nameof(entityType)), + memberType, member, entityType); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/src/EFCore.InMemory/Properties/InMemoryStrings.resx b/src/EFCore.InMemory/Properties/InMemoryStrings.resx index 9d5449aeb74..32f96eba487 100644 --- a/src/EFCore.InMemory/Properties/InMemoryStrings.resx +++ b/src/EFCore.InMemory/Properties/InMemoryStrings.resx @@ -146,4 +146,7 @@ 'UpdateEntityType' called with '{derivedType}' which is not derived type of '{entityType}'. + + Unable to bind '{memberType}' '{member}' to entity projection of '{entityType}'. + \ No newline at end of file diff --git a/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs b/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs index 52238863dd1..ec7dbd62f20 100644 --- a/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs +++ b/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs @@ -102,8 +102,7 @@ public virtual Expression BindProperty([NotNull] IProperty property) && !property.DeclaringEntityType.IsAssignableFrom(EntityType)) { throw new InvalidOperationException( - CoreStrings.EntityProjectionExpressionCalledWithIncorrectInterface( - "BindProperty", nameof(IProperty), EntityType.DisplayName(), $"Property:{property.Name}")); + InMemoryStrings.UnableToBindMemberToEntityProjection("Property", property.Name, EntityType.DisplayName())); } return _readExpressionMap[property]; @@ -121,8 +120,7 @@ public virtual void AddNavigationBinding([NotNull] INavigation navigation, [NotN && !navigation.DeclaringEntityType.IsAssignableFrom(EntityType)) { throw new InvalidOperationException( - CoreStrings.EntityProjectionExpressionCalledWithIncorrectInterface( - "AddNavigationBinding", nameof(INavigation), EntityType.DisplayName(), $"Property:{navigation.Name}")); + InMemoryStrings.UnableToBindMemberToEntityProjection("Navigation", navigation.Name, EntityType.DisplayName())); } _navigationExpressionsCache[navigation] = entityShaper; @@ -140,8 +138,7 @@ public virtual EntityShaperExpression BindNavigation([NotNull] INavigation navig && !navigation.DeclaringEntityType.IsAssignableFrom(EntityType)) { throw new InvalidOperationException( - CoreStrings.EntityProjectionExpressionCalledWithIncorrectInterface( - "BindNavigation", nameof(INavigation), EntityType.DisplayName(), $"Property:{navigation.Name}")); + InMemoryStrings.UnableToBindMemberToEntityProjection("Navigation", navigation.Name, EntityType.DisplayName())); } return _navigationExpressionsCache.TryGetValue(navigation, out var expression) diff --git a/src/EFCore.Relational/Properties/RelationalStrings.Designer.cs b/src/EFCore.Relational/Properties/RelationalStrings.Designer.cs index dc7a49639d4..bc3b2348ab0 100644 --- a/src/EFCore.Relational/Properties/RelationalStrings.Designer.cs +++ b/src/EFCore.Relational/Properties/RelationalStrings.Designer.cs @@ -1071,6 +1071,42 @@ public static string TableNotMappedEntityType([CanBeNull] object entityType, [Ca GetString("TableNotMappedEntityType", nameof(entityType), nameof(table)), entityType, table); + /// + /// Queries performing '{method}' operation must have a deterministic sort order. Rewrite the query to apply an OrderBy clause on the sequence before calling '{method}'. + /// + public static string LastUsedWithoutOrderBy([CanBeNull] object method) + => string.Format( + GetString("LastUsedWithoutOrderBy", nameof(method)), + method); + + /// + /// Null TypeMapping in Sql Tree. + /// + public static string NullTypeMappingInSqlTree + => GetString("NullTypeMappingInSqlTree"); + + /// + /// Unable to bind '{memberType}' '{member}' to entity projection of '{entityType}'. + /// + public static string UnableToBindMemberToEntityProjection([CanBeNull] object memberType, [CanBeNull] object member, [CanBeNull] object entityType) + => string.Format( + GetString("UnableToBindMemberToEntityProjection", nameof(memberType), nameof(member), nameof(entityType)), + memberType, member, entityType); + + /// + /// Unsupported operator '{nodeType}' specified for expression of type '{expressionType}'. + /// + public static string UnsupportedOperatorForSqlExpression([CanBeNull] object nodeType, [CanBeNull] object expressionType) + => string.Format( + GetString("UnsupportedOperatorForSqlExpression", nameof(nodeType), nameof(expressionType)), + nodeType, expressionType); + + /// + /// VisitChildren must be overridden in class deriving from SqlExpression. + /// + public static string VisitChildrenMustBeOverridden + => GetString("VisitChildrenMustBeOverridden"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/src/EFCore.Relational/Properties/RelationalStrings.resx b/src/EFCore.Relational/Properties/RelationalStrings.resx index 8fbec4c83e3..b19546e06ab 100644 --- a/src/EFCore.Relational/Properties/RelationalStrings.resx +++ b/src/EFCore.Relational/Properties/RelationalStrings.resx @@ -747,4 +747,19 @@ The entity type '{entityType}' is not mapped to the store object '{table}'. + + Queries performing '{method}' operation must have a deterministic sort order. Rewrite the query to apply an OrderBy clause on the sequence before calling '{method}'. + + + Null TypeMapping in Sql Tree. + + + Unable to bind '{memberType}' '{member}' to entity projection of '{entityType}'. + + + Unsupported operator '{nodeType}' specified for expression of type '{expressionType}'. + + + VisitChildren must be overridden in class deriving from SqlExpression. + \ No newline at end of file diff --git a/src/EFCore.Relational/Query/EntityProjectionExpression.cs b/src/EFCore.Relational/Query/EntityProjectionExpression.cs index d52eaec22ad..25463476742 100644 --- a/src/EFCore.Relational/Query/EntityProjectionExpression.cs +++ b/src/EFCore.Relational/Query/EntityProjectionExpression.cs @@ -166,11 +166,7 @@ public virtual ColumnExpression BindProperty([NotNull] IProperty property) && !property.DeclaringEntityType.IsAssignableFrom(EntityType)) { throw new InvalidOperationException( - CoreStrings.EntityProjectionExpressionCalledWithIncorrectInterface( - "BindProperty", - "IProperty", - EntityType.DisplayName(), - property.Name)); + RelationalStrings.UnableToBindMemberToEntityProjection("Property", property.Name, EntityType.DisplayName())); } return _propertyExpressionMap[property]; @@ -190,11 +186,7 @@ public virtual void AddNavigationBinding([NotNull] INavigation navigation, [NotN && !navigation.DeclaringEntityType.IsAssignableFrom(EntityType)) { throw new InvalidOperationException( - CoreStrings.EntityProjectionExpressionCalledWithIncorrectInterface( - "AddNavigationBinding", - "INavigation", - EntityType.DisplayName(), - navigation.Name)); + RelationalStrings.UnableToBindMemberToEntityProjection("Navigation", navigation.Name, EntityType.DisplayName())); } _ownedNavigationMap[navigation] = entityShaper; @@ -214,11 +206,7 @@ public virtual EntityShaperExpression BindNavigation([NotNull] INavigation navig && !navigation.DeclaringEntityType.IsAssignableFrom(EntityType)) { throw new InvalidOperationException( - CoreStrings.EntityProjectionExpressionCalledWithIncorrectInterface( - "BindNavigation", - "INavigation", - EntityType.DisplayName(), - navigation.Name)); + RelationalStrings.UnableToBindMemberToEntityProjection("Navigation", navigation.Name, EntityType.DisplayName())); } return _ownedNavigationMap.TryGetValue(navigation, out var expression) diff --git a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs index 33d59eed596..3d4f4ddd857 100644 --- a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs @@ -663,7 +663,7 @@ protected override ShapedQueryExpression TranslateLastOrDefault( if (selectExpression.Orderings.Count == 0) { throw new InvalidOperationException( - CoreStrings.LastUsedWithoutOrderBy(returnDefault ? + RelationalStrings.LastUsedWithoutOrderBy(returnDefault ? nameof(Queryable.LastOrDefault) : nameof(Queryable.Last))); } @@ -1559,7 +1559,7 @@ private ShapedQueryExpression AggregateResultShaper( Expression.New( typeof(InvalidOperationException).GetConstructors() .Single(ci => ci.GetParameters().Length == 1), - Expression.Constant(CoreStrings.NoElements)), + Expression.Constant(CoreStrings.SequenceContainsNoElements)), resultType); shaper = Expression.Block( diff --git a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs index f9fc462e07c..82d91a3402f 100644 --- a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs @@ -1540,7 +1540,7 @@ protected override Expression VisitExtension(Expression extensionExpression) { if (sqlExpression.TypeMapping == null) { - throw new InvalidOperationException(CoreStrings.NullTypeMappingInSqlTree); + throw new InvalidOperationException(RelationalStrings.NullTypeMappingInSqlTree); } } diff --git a/src/EFCore.Relational/Query/SqlExpressionFactory.cs b/src/EFCore.Relational/Query/SqlExpressionFactory.cs index 8b058c7835c..f3fbb45bacc 100644 --- a/src/EFCore.Relational/Query/SqlExpressionFactory.cs +++ b/src/EFCore.Relational/Query/SqlExpressionFactory.cs @@ -150,7 +150,8 @@ private SqlExpression ApplyTypeMappingOnSqlUnary( break; default: - throw new InvalidOperationException(CoreStrings.UnsupportedUnary); + throw new InvalidOperationException(RelationalStrings.UnsupportedOperatorForSqlExpression( + sqlUnaryExpression.OperatorType, typeof(SqlUnaryExpression).ShortDisplayName())); } return new SqlUnaryExpression(sqlUnaryExpression.OperatorType, operand, resultType, resultTypeMapping); @@ -208,7 +209,8 @@ private SqlExpression ApplyTypeMappingOnSqlBinary( } default: - throw new InvalidOperationException(CoreStrings.IncorrectOperatorType); + throw new InvalidOperationException(RelationalStrings.UnsupportedOperatorForSqlExpression( + sqlBinaryExpression.OperatorType, typeof(SqlBinaryExpression).ShortDisplayName())); } return new SqlBinaryExpression( diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlBinaryExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlBinaryExpression.cs index 42d6fa26be7..3946188227e 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlBinaryExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlBinaryExpression.cs @@ -6,6 +6,7 @@ using System.Linq.Expressions; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; @@ -70,7 +71,8 @@ public SqlBinaryExpression( if (!IsValidOperator(operatorType)) { - throw new InvalidOperationException(CoreStrings.UnsupportedBinaryOperator); + throw new InvalidOperationException(RelationalStrings.UnsupportedOperatorForSqlExpression( + operatorType, typeof(SqlBinaryExpression).ShortDisplayName())); } OperatorType = operatorType; diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlExpression.cs index 1edfc006b57..d800204368e 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlExpression.cs @@ -46,7 +46,7 @@ protected SqlExpression([NotNull] Type type, [CanBeNull] RelationalTypeMapping t /// protected override Expression VisitChildren(ExpressionVisitor visitor) - => throw new InvalidOperationException(CoreStrings.VisitChildrenMustBeOverridden); + => throw new InvalidOperationException(RelationalStrings.VisitChildrenMustBeOverridden); /// public sealed override ExpressionType NodeType => ExpressionType.Extension; diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlUnaryExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlUnaryExpression.cs index c0fa1f15ba2..b00410d08da 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlUnaryExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlUnaryExpression.cs @@ -6,6 +6,7 @@ using System.Linq.Expressions; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; @@ -53,7 +54,8 @@ public SqlUnaryExpression( if (!IsValidOperator(operatorType)) { - throw new InvalidOperationException(CoreStrings.UnsupportedUnary); + throw new InvalidOperationException(RelationalStrings.UnsupportedOperatorForSqlExpression( + operatorType, typeof(SqlUnaryExpression).ShortDisplayName())); } OperatorType = operatorType; diff --git a/src/EFCore/Properties/CoreStrings.Designer.cs b/src/EFCore/Properties/CoreStrings.Designer.cs index 232603a907c..7e5957d3582 100644 --- a/src/EFCore/Properties/CoreStrings.Designer.cs +++ b/src/EFCore/Properties/CoreStrings.Designer.cs @@ -64,12 +64,6 @@ public static string ModelNotFinalized([CanBeNull] object method) GetString("ModelNotFinalized", nameof(method)), method); - /// - /// Sequence contains no elements. - /// - public static string NoElements - => GetString("NoElements"); - /// /// The given 'IQueryable' does not support generation of query strings. /// @@ -387,7 +381,7 @@ public static string NoGetter([CanBeNull] object property, [CanBeNull] object en property, entity, pam); /// - /// The CLR entity materializer cannot be used for entity type '{entityType}' because it is a shadow state entity type. Materialization to a CLR type is only possible for entity types that have a corresponding CLR type. + /// The CLR entity materializer cannot be used for entity type '{entityType}' because it is a shadow state entity type. Materialization to a CLR type is only possible for entity types that have a corresponding CLR type. /// public static string NoClrType([CanBeNull] object entityType) => string.Format( @@ -837,7 +831,7 @@ public static string RelationshipCannotBeInverted => GetString("RelationshipCannotBeInverted"); /// - /// The specified type '{type}'must be a non-interface reference type to be used as an entity type . + /// The specified type '{type}'must be a non-interface reference type to be used as an entity type. /// public static string InvalidEntityType([CanBeNull] object type) => string.Format( @@ -2233,6 +2227,7 @@ public static string SetOperationWithDifferentIncludesInOperands /// /// Include is not supported for entities with defining query. Entity type: '{entityType}' /// + [Obsolete] public static string IncludeOnEntityWithDefiningQueryNotSupported([CanBeNull] object entityType) => string.Format( GetString("IncludeOnEntityWithDefiningQueryNotSupported", nameof(entityType)), @@ -2382,14 +2377,6 @@ public static string SkipNavigationInUseBySkipNavigation([CanBeNull] object skip GetString("SkipNavigationInUseBySkipNavigation", nameof(skipNavigation), nameof(inverseSkipNavigation), nameof(referencingEntityType)), skipNavigation, inverseSkipNavigation, referencingEntityType); - /// - /// Queries performing '{method}' operation must have a deterministic sort order. Rewrite the query to apply an OrderBy clause on the sequence before calling '{method}'. - /// - public static string LastUsedWithoutOrderBy([CanBeNull] object method) - => string.Format( - GetString("LastUsedWithoutOrderBy", nameof(method)), - method); - /// /// Immediate convention scope cannot be run again. /// @@ -2420,14 +2407,6 @@ public static string UnhandledMemberBinding([CanBeNull] object bindingType) GetString("UnhandledMemberBinding", nameof(bindingType)), bindingType); - /// - /// Invalid include path '{navigationChain}', couldn't find navigation for '{navigationName}'. - /// - public static string InvalidIncludePath([CanBeNull] object navigationChain, [CanBeNull] object navigationName) - => string.Format( - GetString("InvalidIncludePath", nameof(navigationChain), nameof(navigationName)), - navigationChain, navigationName); - /// /// Lambda expression used inside Include is not valid. /// @@ -2508,44 +2487,6 @@ public static string VisitIsNotAllowed([CanBeNull] object visitMethodName) GetString("VisitIsNotAllowed", nameof(visitMethodName)), visitMethodName); - /// - /// Called EntityProjectionExpression.{methodName}() with incorrect {interfaceType}. EntityType:{entityType}, {entityValue} - /// - public static string EntityProjectionExpressionCalledWithIncorrectInterface([CanBeNull] object methodName, [CanBeNull] object interfaceType, [CanBeNull] object entityType, [CanBeNull] object entityValue) - => string.Format( - GetString("EntityProjectionExpressionCalledWithIncorrectInterface", nameof(methodName), nameof(interfaceType), nameof(entityType), nameof(entityValue)), - methodName, interfaceType, entityType, entityValue); - - /// - /// Unsupported Unary operator type specified. - /// - public static string UnsupportedUnary - => GetString("UnsupportedUnary"); - - /// - /// Incorrect operatorType for SqlBinaryExpression. - /// - public static string IncorrectOperatorType - => GetString("IncorrectOperatorType"); - - /// - /// Null TypeMapping in Sql Tree. - /// - public static string NullTypeMappingInSqlTree - => GetString("NullTypeMappingInSqlTree"); - - /// - /// VisitChildren must be overridden in class deriving from SqlExpression. - /// - public static string VisitChildrenMustBeOverridden - => GetString("VisitChildrenMustBeOverridden"); - - /// - /// Unsupported Binary operator type specified. - /// - public static string UnsupportedBinaryOperator - => GetString("UnsupportedBinaryOperator"); - /// /// Translation of '{expression}' failed. Either source is not an entity type or the specified property does not exist on the entity type. /// @@ -2576,20 +2517,6 @@ public static string QueryUnableToTranslateMethod([CanBeNull] object declaringTy GetString("QueryUnableToTranslateMethod", nameof(declaringTypeName), nameof(methodName)), declaringTypeName, methodName); - /// - /// Invalid {state} encountered. - /// - public static string InvalidStateEncountered([CanBeNull] object state) - => string.Format( - GetString("InvalidStateEncountered", nameof(state)), - state); - - /// - /// Cannot apply DefaultIfEmpty after a client-evaluated projection. - /// - public static string DefaultIfEmptyAppliedAfterProjection - => GetString("DefaultIfEmptyAppliedAfterProjection"); - /// /// Invalid {name}: {value} /// diff --git a/src/EFCore/Properties/CoreStrings.resx b/src/EFCore/Properties/CoreStrings.resx index 21ae743bc56..0ef1cbb9783 100644 --- a/src/EFCore/Properties/CoreStrings.resx +++ b/src/EFCore/Properties/CoreStrings.resx @@ -132,9 +132,6 @@ The model must be finalized before '{method}' can be used. Ensure that either 'OnModelCreating' has completed or, if using a stand-alone 'ModelBuilder', that 'FinalizeModel' has been called. - - Sequence contains no elements. - The given 'IQueryable' does not support generation of query strings. @@ -258,7 +255,7 @@ The property '{property}' of entity type '{entity}' does not have a getter. Either make the property readable or use a different '{pam}'. - The CLR entity materializer cannot be used for entity type '{entityType}' because it is a shadow state entity type. Materialization to a CLR type is only possible for entity types that have a corresponding CLR type. + The CLR entity materializer cannot be used for entity type '{entityType}' because it is a shadow state entity type. Materialization to a CLR type is only possible for entity types that have a corresponding CLR type. Services for database providers {storeNames} have been registered in the service provider. Only a single database provider can be registered in a service provider. If possible, ensure that Entity Framework is managing its service provider by removing the call to UseInternalServiceProvider. Otherwise, consider conditionally registering the database provider, or maintaining one service provider per database provider. @@ -568,7 +565,7 @@ The principal and dependent ends of the relationship cannot be flipped once foreign key or principal key properties have been specified. - The specified type '{type}'must be a non-interface reference type to be used as an entity type . + The specified type '{type}'must be a non-interface reference type to be used as an entity type. The relationship from '{referencingEntityTypeOrNavigation}' to '{referencedEntityTypeOrNavigation}' with foreign key properties {foreignKeyPropertiesWithTypes} cannot target the primary key {primaryKeyPropertiesWithTypes} because it is not compatible. Configure a principal key or a set of compatible foreign key properties for this relationship. @@ -1215,6 +1212,7 @@ Include is not supported for entities with defining query. Entity type: '{entityType}' + Obsolete The RequiredAttribute on '{principalEntityType}.{principalNavigation}' was ignored because it is a collection. RequiredAttribute should only be specified on reference navigations pointing to the principal side of the relationship. @@ -1286,9 +1284,6 @@ The skip navigation '{skipNavigation}' cannot be removed because it is set as the inverse of the skip navigation '{inverseSkipNavigation}' on '{referencingEntityType}'. All referencing skip navigations must be removed before this skip navigation can be removed. - - Queries performing '{method}' operation must have a deterministic sort order. Rewrite the query to apply an OrderBy clause on the sequence before calling '{method}'. - Immediate convention scope cannot be run again. @@ -1301,9 +1296,6 @@ Unhandled member binding type '{bindingType}'. - - Invalid include path '{navigationChain}', couldn't find navigation for '{navigationName}'. - Lambda expression used inside Include is not valid. @@ -1340,24 +1332,6 @@ Calling '{visitMethodName}' is not allowed. Visit expression manually for relevant part. - - Called EntityProjectionExpression.{methodName}() with incorrect {interfaceType}. EntityType:{entityType}, {entityValue} - - - Unsupported Unary operator type specified. - - - Incorrect operatorType for SqlBinaryExpression. - - - Null TypeMapping in Sql Tree. - - - VisitChildren must be overridden in class deriving from SqlExpression. - - - Unsupported Binary operator type specified. - Translation of '{expression}' failed. Either source is not an entity type or the specified property does not exist on the entity type. @@ -1370,12 +1344,6 @@ Translation of method '{declaringTypeName}.{methodName}' failed. If you are trying to map your custom function, see https://go.microsoft.com/fwlink/?linkid=2132413 for more information. - - Invalid {state} encountered. - - - Cannot apply DefaultIfEmpty after a client-evaluated projection. - Conflicting attributes have been applied: the 'Key' attribute on property '{property}' and the 'Keyless' attribute on its entity '{entity}'. Note that the entity will have no key unless you use fluent API to override this. Warning CoreEventId.ConflictingKeylessAndKeyAttributesWarning string string diff --git a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs index 96b80ebea73..39583b93f73 100644 --- a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs @@ -814,7 +814,9 @@ private NavigationExpansionExpression ProcessInclude(NavigationExpansionExpressi if (entityReference.EntityType.GetDefiningQuery() != null) { throw new InvalidOperationException( +#pragma warning disable CS0612 // Type or member is obsolete CoreStrings.IncludeOnEntityWithDefiningQueryNotSupported(entityReference.EntityType.DisplayName())); +#pragma warning restore CS0612 // Type or member is obsolete } #pragma warning restore CS0618 // Type or member is obsolete diff --git a/test/EFCore.InMemory.FunctionalTests/Query/NorthwindAggregateOperatorsQueryInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/NorthwindAggregateOperatorsQueryInMemoryTest.cs index f9ef1b06484..9ab2f975946 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/NorthwindAggregateOperatorsQueryInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/NorthwindAggregateOperatorsQueryInMemoryTest.cs @@ -65,18 +65,6 @@ public override Task Contains_with_local_tuple_array_closure(bool async) return base.Contains_with_local_tuple_array_closure(async); } - [ConditionalTheory(Skip = "Issue#17386")] - public override Task Last_when_no_order_by(bool async) - { - return base.Last_when_no_order_by(async); - } - - [ConditionalTheory(Skip = "Issue#17386")] - public override Task LastOrDefault_when_no_order_by(bool async) - { - return base.LastOrDefault_when_no_order_by(async); - } - [ConditionalFact(Skip = "Issue#20023")] public override void Contains_over_keyless_entity_throws() { diff --git a/test/EFCore.InMemory.FunctionalTests/Query/NorthwindIncludeNoTrackingQueryInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/NorthwindIncludeNoTrackingQueryInMemoryTest.cs index 91c24456d75..03fd85c7ece 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/NorthwindIncludeNoTrackingQueryInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/NorthwindIncludeNoTrackingQueryInMemoryTest.cs @@ -1,9 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.TestUtilities; -using Xunit; using Xunit.Abstractions; namespace Microsoft.EntityFrameworkCore.Query @@ -15,11 +13,5 @@ public NorthwindIncludeNoTrackingQueryInMemoryTest(NorthwindQueryInMemoryFixture { //TestLoggerFactory.TestOutputHelper = testOutputHelper; } - - [ConditionalTheory(Skip = "Issue#17386")] - public override Task Include_collection_with_last_no_orderby(bool async) - { - return base.Include_collection_with_last_no_orderby(async); - } } } diff --git a/test/EFCore.InMemory.FunctionalTests/Query/NorthwindIncludeQueryInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/NorthwindIncludeQueryInMemoryTest.cs index 6bf8f70cf0b..9b9a650413b 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/NorthwindIncludeQueryInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/NorthwindIncludeQueryInMemoryTest.cs @@ -1,9 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.TestUtilities; -using Xunit; using Xunit.Abstractions; namespace Microsoft.EntityFrameworkCore.Query @@ -15,11 +13,5 @@ public NorthwindIncludeQueryInMemoryTest(NorthwindQueryInMemoryFixture( + () => base.Last_when_no_order_by(async))).Message); + } + + public override async Task LastOrDefault_when_no_order_by(bool async) + { + Assert.Equal(RelationalStrings.LastUsedWithoutOrderBy(nameof(Enumerable.LastOrDefault)), + (await Assert.ThrowsAsync( + () => base.LastOrDefault_when_no_order_by(async))).Message); + } + protected virtual bool CanExecuteQueryString => false; protected override QueryAsserter CreateQueryAsserter(TFixture fixture) diff --git a/test/EFCore.Relational.Specification.Tests/Query/NorthwindIncludeQueryRelationalTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/NorthwindIncludeQueryRelationalTestBase.cs index feb20e86798..4989ae384b7 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/NorthwindIncludeQueryRelationalTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/NorthwindIncludeQueryRelationalTestBase.cs @@ -1,7 +1,12 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; namespace Microsoft.EntityFrameworkCore.Query { @@ -13,6 +18,14 @@ protected NorthwindIncludeQueryRelationalTestBase(TFixture fixture) { } + public override async Task Include_collection_with_last_no_orderby(bool async) + { + Assert.Equal( + RelationalStrings.LastUsedWithoutOrderBy(nameof(Enumerable.Last)), + (await Assert.ThrowsAsync( + () => base.Include_collection_with_last_no_orderby(async))).Message); + } + protected virtual bool CanExecuteQueryString => false; protected override QueryAsserter CreateQueryAsserter(TFixture fixture) diff --git a/test/EFCore.Relational.Specification.Tests/Query/NorthwindSplitIncludeNoTrackingQueryTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/NorthwindSplitIncludeNoTrackingQueryTestBase.cs index 249aff4ed19..33a6d419132 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/NorthwindSplitIncludeNoTrackingQueryTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/NorthwindSplitIncludeNoTrackingQueryTestBase.cs @@ -118,15 +118,10 @@ var orders Assert.Single(context.ChangeTracker.Entries()); } - public override async Task Include_collection_with_last_no_orderby(bool async) + public override Task Include_collection_with_last_no_orderby(bool async) { - Assert.Equal( - CoreStrings.TranslationFailed("DbSet() .Reverse()"), - (await Assert.ThrowsAsync( - () => AssertLast( - async, - ss => ss.Set().Include(c => c.Orders), - entryCount: 8))).Message.Replace("\r", "").Replace("\n", "")); + return AssertTranslationFailedWithDetails( + () => base.Include_collection_with_last_no_orderby(async), RelationalStrings.MissingOrderingInSqlExpression); } [ConditionalTheory(Skip = "Collection Include on nested collection")] diff --git a/test/EFCore.Relational.Specification.Tests/Query/NorthwindSplitIncludeQueryTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/NorthwindSplitIncludeQueryTestBase.cs index b3775ba83e6..f9a0d9d6ff1 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/NorthwindSplitIncludeQueryTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/NorthwindSplitIncludeQueryTestBase.cs @@ -108,15 +108,10 @@ var orders Assert.Equal(7, context.ChangeTracker.Entries().Count()); } - public override async Task Include_collection_with_last_no_orderby(bool async) + public override Task Include_collection_with_last_no_orderby(bool async) { - Assert.Equal( - CoreStrings.TranslationFailed("DbSet() .Reverse()"), - (await Assert.ThrowsAsync( - () => AssertLast( - async, - ss => ss.Set().Include(c => c.Orders), - entryCount: 8))).Message.Replace("\r","").Replace("\n","")); + return AssertTranslationFailedWithDetails( + () => base.Include_collection_with_last_no_orderby(async), RelationalStrings.MissingOrderingInSqlExpression); } [ConditionalTheory(Skip = "Collection Include on nested collection")] diff --git a/test/EFCore.Specification.Tests/Query/NorthwindAggregateOperatorsQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindAggregateOperatorsQueryTestBase.cs index b37cfea96e8..9a1e0c38631 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindAggregateOperatorsQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindAggregateOperatorsQueryTestBase.cs @@ -981,28 +981,22 @@ public virtual Task Last(bool async) [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual async Task Last_when_no_order_by(bool async) + public virtual Task Last_when_no_order_by(bool async) { - Assert.Equal(Diagnostics.CoreStrings.LastUsedWithoutOrderBy(nameof(Enumerable.Last)), - (await Assert.ThrowsAsync( - () => AssertLast( - async, - ss => ss.Set().Where(c => c.CustomerID == "ALFKI"), - entryCount: 1) - )).Message); + return AssertLast( + async, + ss => ss.Set().Where(c => c.CustomerID == "ALFKI"), + entryCount: 1); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual async Task LastOrDefault_when_no_order_by(bool async) + public virtual Task LastOrDefault_when_no_order_by(bool async) { - Assert.Equal(Diagnostics.CoreStrings.LastUsedWithoutOrderBy(nameof(Enumerable.LastOrDefault)), - (await Assert.ThrowsAsync( - () => AssertLastOrDefault( - async, - ss => ss.Set().Where(c => c.CustomerID == "ALFKI"), - entryCount: 1) - )).Message); + return AssertLastOrDefault( + async, + ss => ss.Set().Where(c => c.CustomerID == "ALFKI"), + entryCount: 1); } [ConditionalTheory] diff --git a/test/EFCore.Specification.Tests/Query/NorthwindIncludeQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindIncludeQueryTestBase.cs index fec4d8b42b5..0a0d10fd6c4 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindIncludeQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindIncludeQueryTestBase.cs @@ -178,15 +178,12 @@ public virtual Task Include_collection_with_last(bool async) [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual async Task Include_collection_with_last_no_orderby(bool async) + public virtual Task Include_collection_with_last_no_orderby(bool async) { - Assert.Equal( - CoreStrings.LastUsedWithoutOrderBy(nameof(Enumerable.Last)), - (await Assert.ThrowsAsync( - () => AssertLast( - async, - ss => ss.Set().Include(c => c.Orders), - entryCount: 8))).Message); + return AssertLast( + async, + ss => ss.Set().Include(c => c.Orders), + entryCount: 8); } [ConditionalTheory] diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindIncludeNoTrackingQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindIncludeNoTrackingQuerySqlServerTest.cs index f8d8d6b3af9..90135d75906 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindIncludeNoTrackingQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindIncludeNoTrackingQuerySqlServerTest.cs @@ -1,7 +1,12 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; namespace Microsoft.EntityFrameworkCore.Query { @@ -13,5 +18,13 @@ public NorthwindIncludeNoTrackingQuerySqlServerTest(NorthwindQuerySqlServerFixtu { Fixture.TestSqlLoggerFactory.Clear(); } + + public override async Task Include_collection_with_last_no_orderby(bool async) + { + Assert.Equal( + RelationalStrings.LastUsedWithoutOrderBy(nameof(Enumerable.Last)), + (await Assert.ThrowsAsync( + () => base.Include_collection_with_last_no_orderby(async))).Message); + } } } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeNoTrackingQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeNoTrackingQuerySqlServerTest.cs index 6104e4f8e17..11dd468e374 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeNoTrackingQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeNoTrackingQuerySqlServerTest.cs @@ -1,12 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.TestModels.Northwind; using Microsoft.EntityFrameworkCore.TestUtilities; -using Xunit; using Xunit.Abstractions; namespace Microsoft.EntityFrameworkCore.Query @@ -20,15 +15,5 @@ public NorthwindSplitIncludeNoTrackingQuerySqlServerTest(NorthwindQuerySqlServer Fixture.TestSqlLoggerFactory.Clear(); //Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } - - public override Task Include_collection_with_last_no_orderby(bool async) - { - return AssertTranslationFailedWithDetails( - () => AssertLast( - async, - ss => ss.Set().Include(c => c.Orders), - entryCount: 8 - ), RelationalStrings.MissingOrderingInSqlExpression); - } } } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeQuerySqlServerTest.cs index 30fc4f0d87c..72472dca73d 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeQuerySqlServerTest.cs @@ -3,8 +3,6 @@ using System; using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.TestModels.Northwind; using Microsoft.EntityFrameworkCore.TestUtilities; using Xunit; using Xunit.Abstractions; @@ -1761,16 +1759,6 @@ FROM [Customers] AS [c] ORDER BY [c].[CustomerID], [o].[OrderID]"); } - public override Task Include_collection_with_last_no_orderby(bool async) - { - return AssertTranslationFailedWithDetails( - () => AssertLast( - async, - ss => ss.Set().Include(c => c.Orders), - entryCount: 8 - ), RelationalStrings.MissingOrderingInSqlExpression); - } - private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindStringIncludeQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindStringIncludeQuerySqlServerTest.cs index 0b3dcd2b89f..3a68631122a 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindStringIncludeQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindStringIncludeQuerySqlServerTest.cs @@ -1,7 +1,12 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; namespace Microsoft.EntityFrameworkCore.Query { @@ -13,5 +18,13 @@ public NorthwindStringIncludeQuerySqlServerTest(NorthwindQuerySqlServerFixture( + () => base.Include_collection_with_last_no_orderby(async))).Message); + } } } diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindIncludeNoTrackingQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindIncludeNoTrackingQuerySqliteTest.cs index 6e1704143b6..04d07d549a8 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindIncludeNoTrackingQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindIncludeNoTrackingQuerySqliteTest.cs @@ -2,7 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Linq; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Sqlite.Internal; using Microsoft.EntityFrameworkCore.TestUtilities; using Xunit; @@ -41,5 +43,13 @@ public override async Task Include_collection_with_outer_apply_with_filter_non_e SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( () => base.Include_collection_with_outer_apply_with_filter_non_equality(async))).Message); + + public override async Task Include_collection_with_last_no_orderby(bool async) + { + Assert.Equal( + RelationalStrings.LastUsedWithoutOrderBy(nameof(Enumerable.Last)), + (await Assert.ThrowsAsync( + () => base.Include_collection_with_last_no_orderby(async))).Message); + } } } diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindSplitIncludeNoTrackingQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindSplitIncludeNoTrackingQuerySqliteTest.cs index 001eb3f481a..5524f12e87a 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindSplitIncludeNoTrackingQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindSplitIncludeNoTrackingQuerySqliteTest.cs @@ -3,9 +3,7 @@ using System; using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Sqlite.Internal; -using Microsoft.EntityFrameworkCore.TestModels.Northwind; using Microsoft.EntityFrameworkCore.TestUtilities; using Xunit; using Xunit.Abstractions; @@ -43,15 +41,5 @@ public override async Task Include_collection_with_outer_apply_with_filter_non_e SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( () => base.Include_collection_with_outer_apply_with_filter_non_equality(async))).Message); - - public override Task Include_collection_with_last_no_orderby(bool async) - { - return AssertTranslationFailedWithDetails( - () => AssertLast( - async, - ss => ss.Set().Include(c => c.Orders), - entryCount: 8 - ), RelationalStrings.MissingOrderingInSqlExpression); - } } } diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindSplitIncludeQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindSplitIncludeQuerySqliteTest.cs index 17c91a43e4b..d3fa3954af5 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindSplitIncludeQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindSplitIncludeQuerySqliteTest.cs @@ -3,9 +3,7 @@ using System; using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Sqlite.Internal; -using Microsoft.EntityFrameworkCore.TestModels.Northwind; using Microsoft.EntityFrameworkCore.TestUtilities; using Xunit; using Xunit.Abstractions; @@ -43,15 +41,5 @@ public override async Task Include_collection_with_outer_apply_with_filter_non_e SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( () => base.Include_collection_with_outer_apply_with_filter_non_equality(async))).Message); - - public override Task Include_collection_with_last_no_orderby(bool async) - { - return AssertTranslationFailedWithDetails( - () => AssertLast( - async, - ss => ss.Set().Include(c => c.Orders), - entryCount: 8 - ), RelationalStrings.MissingOrderingInSqlExpression); - } } } diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindStringIncludeQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindStringIncludeQuerySqliteTest.cs index fdd5441fea9..ffde5bcdd51 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindStringIncludeQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindStringIncludeQuerySqliteTest.cs @@ -2,7 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Linq; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Sqlite.Internal; using Microsoft.EntityFrameworkCore.TestUtilities; using Xunit; @@ -35,5 +37,13 @@ public override async Task Include_collection_with_outer_apply_with_filter_non_e SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( () => base.Include_collection_with_outer_apply_with_filter_non_equality(async))).Message); + + public override async Task Include_collection_with_last_no_orderby(bool async) + { + Assert.Equal( + RelationalStrings.LastUsedWithoutOrderBy(nameof(Enumerable.Last)), + (await Assert.ThrowsAsync( + () => base.Include_collection_with_last_no_orderby(async))).Message); + } } }