From 9aaec852094f61ed1618b2c19240308f1d9ba6d5 Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Tue, 1 Sep 2020 13:45:15 -0700 Subject: [PATCH] Print expression when throwing null type mapping in SQL tree Part of #7201 --- .../Properties/CosmosStrings.Designer.cs | 8 +++++--- src/EFCore.Cosmos/Properties/CosmosStrings.resx | 2 +- .../CosmosSqlTranslatingExpressionVisitor.cs | 2 +- .../Properties/RelationalStrings.Designer.cs | 12 ++++++++---- .../Properties/RelationalStrings.resx | 2 +- .../RelationalSqlTranslatingExpressionVisitor.cs | 2 +- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs b/src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs index 1490597e07a..ae23dd0bc77 100644 --- a/src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs +++ b/src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs @@ -163,10 +163,12 @@ public static string NoReadItemQueryString([CanBeNull] object resourceId, [CanBe resourceId, partitionKey); /// - /// Null TypeMapping in Sql Tree. + /// Expression '{sqlExpression}' in SQL tree does not have type mapping assigned. /// - public static string NullTypeMappingInSqlTree - => GetString("NullTypeMappingInSqlTree"); + public static string NullTypeMappingInSqlTree([CanBeNull] object sqlExpression) + => string.Format( + GetString("NullTypeMappingInSqlTree", nameof(sqlExpression)), + sqlExpression); /// /// Offset is not supported without Limit. diff --git a/src/EFCore.Cosmos/Properties/CosmosStrings.resx b/src/EFCore.Cosmos/Properties/CosmosStrings.resx index 4f7c2c8129e..285edc4c8c2 100644 --- a/src/EFCore.Cosmos/Properties/CosmosStrings.resx +++ b/src/EFCore.Cosmos/Properties/CosmosStrings.resx @@ -175,7 +175,7 @@ There is no string-based representation of this query as it's executed using 'ReadItemQueryAsync({resourceId}, {partitionKey})'. - Null TypeMapping in Sql Tree. + Expression '{sqlExpression}' in SQL tree does not have type mapping assigned. Offset is not supported without Limit. diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs index 326ef526292..8e5e560d700 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs @@ -987,7 +987,7 @@ protected override Expression VisitExtension(Expression extensionExpression) if (extensionExpression is SqlExpression sqlExpression && sqlExpression.TypeMapping == null) { - throw new InvalidOperationException(CosmosStrings.NullTypeMappingInSqlTree); + throw new InvalidOperationException(CosmosStrings.NullTypeMappingInSqlTree(sqlExpression.Print())); } return base.VisitExtension(extensionExpression); diff --git a/src/EFCore.Relational/Properties/RelationalStrings.Designer.cs b/src/EFCore.Relational/Properties/RelationalStrings.Designer.cs index 0c0cf4315ce..dc8b8fc5f64 100644 --- a/src/EFCore.Relational/Properties/RelationalStrings.Designer.cs +++ b/src/EFCore.Relational/Properties/RelationalStrings.Designer.cs @@ -697,7 +697,9 @@ public static string MissingConcurrencyColumn([CanBeNull] object entityType, [Ca /// Collection subquery that uses 'Distinct' or 'Group By' operations must project key columns of all of it's tables. Missing column: {column}. Either add column(s) to the projection or rewrite query to not use 'GroupBy'/'Distinct' operation. /// public static string MissingIdentifyingProjectionInDistinctGroupBySubquery([CanBeNull] object column) - => string.Format(GetString("MissingIdentifyingProjectionInDistinctGroupBySubquery", nameof(column)), column); + => string.Format( + GetString("MissingIdentifyingProjectionInDistinctGroupBySubquery", nameof(column)), + column); /// /// Reverse could not be translated to the server because there is no ordering on the server side. @@ -810,10 +812,12 @@ public static string NullabilityInfoOnlyAllowedOnScalarFunctions => GetString("NullabilityInfoOnlyAllowedOnScalarFunctions"); /// - /// Null TypeMapping in Sql Tree. + /// Expression '{sqlExpression}' in SQL tree does not have type mapping assigned. /// - public static string NullTypeMappingInSqlTree - => GetString("NullTypeMappingInSqlTree"); + public static string NullTypeMappingInSqlTree([CanBeNull] object sqlExpression) + => string.Format( + GetString("NullTypeMappingInSqlTree", nameof(sqlExpression)), + sqlExpression); /// /// Cannot use the value provided for parameter '{parameter}' because it isn't assignable to type object[]. diff --git a/src/EFCore.Relational/Properties/RelationalStrings.resx b/src/EFCore.Relational/Properties/RelationalStrings.resx index ac3476f4bdb..b9912755098 100644 --- a/src/EFCore.Relational/Properties/RelationalStrings.resx +++ b/src/EFCore.Relational/Properties/RelationalStrings.resx @@ -647,7 +647,7 @@ Nullability information should only be specified for scalar database functions. - Null TypeMapping in Sql Tree. + Expression '{sqlExpression}' in SQL tree does not have type mapping assigned. Cannot use the value provided for parameter '{parameter}' because it isn't assignable to type object[]. diff --git a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs index 31e5c090df6..2530c390a0a 100644 --- a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs @@ -1579,7 +1579,7 @@ protected override Expression VisitExtension(Expression extensionExpression) { if (sqlExpression.TypeMapping == null) { - throw new InvalidOperationException(RelationalStrings.NullTypeMappingInSqlTree); + throw new InvalidOperationException(RelationalStrings.NullTypeMappingInSqlTree(sqlExpression.Print())); } }