Skip to content

Commit

Permalink
Improve exception messages
Browse files Browse the repository at this point in the history
Part of #7201
Fixes #20951
  • Loading branch information
AndriySvyryd committed Sep 28, 2020
1 parent dfdec47 commit 19d6f7a
Show file tree
Hide file tree
Showing 28 changed files with 319 additions and 291 deletions.
2 changes: 1 addition & 1 deletion src/EFCore.Proxies/Properties/ProxiesStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/EFCore.Proxies/Properties/ProxiesStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
<value>The type '{dictionaryType}' used for shared entity type '{entityType}' is not suitable for use as a change-tracking proxy because its indexer property is not virtual. Consider using an implementation of '{interfaceType}' that allows overriding of the indexer.</value>
</data>
<data name="EntityTypeNotFoundShared" xml:space="preserve">
<value>The type '{clrType}' is configured as a shared-type entity type, but the entity type name is not known. Ensure that CreateProxy is called on a DbSet created specifically for the shared-type entity type through use of a `DbContext.Set` overload that accepts an entity type name.</value>
<value>The type '{clrType}' is configured as a shared-type entity type, but the entity type name is not known. Ensure that CreateProxy is called on a DbSet created specifically for the shared-type entity type through use of a 'DbContext.Set' overload that accepts an entity type name.</value>
</data>
<data name="EntityTypeNotFoundWeak" xml:space="preserve">
<value>Cannot create a proxy for '{typeName}' because it is mapped to multiple owned entity types. Proxy creation is not supported for owned types used more than once in the model.</value>
Expand Down
10 changes: 5 additions & 5 deletions src/EFCore.Relational/Properties/RelationalStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/EFCore.Relational/Properties/RelationalStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
<value>There is no entity type mapped to the table '{table}' used in a data operation. Either add the corresponding entity type to the model or specify the column types in the data operation.</value>
</data>
<data name="DbFunctionExpressionIsNotMethodCall" xml:space="preserve">
<value>The provided DbFunction expression '{expression}' is invalid. The expression should be a lambda expression containing a single method call to the target static method. Default values can be provided as arguments if required. E.g. () =&gt; SomeClass.SomeMethod(null, 0)</value>
<value>The provided DbFunction expression '{expression}' is invalid. The expression should be a lambda expression containing a single method call to the target static method. Default values can be provided as arguments if required. E.g. '() =&gt; SomeClass.SomeMethod(null, 0)'.</value>
</data>
<data name="DbFunctionGenericMethodNotSupported" xml:space="preserve">
<value>The DbFunction '{function}' is generic. Mapping generic methods as a DbFunction is not supported.</value>
Expand Down Expand Up @@ -257,7 +257,7 @@
<value>'{entityType1}.{property1}' and '{entityType2}.{property2}' are both mapped to column '{columnName}' in '{table}' but are configured with different scale ('{scale1}' and '{scale2}').</value>
</data>
<data name="DuplicateColumnNameUnicodenessMismatch" xml:space="preserve">
<value>'{entityType1}.{property1}' and '{entityType2}.{property2}' are both mapped to column '{columnName}' in '{table}' but are configured with different unicode configuration</value>
<value>'{entityType1}.{property1}' and '{entityType2}.{property2}' are both mapped to column '{columnName}' in '{table}' but are configured with different unicode configuration.</value>
</data>
<data name="DuplicateForeignKeyColumnMismatch" xml:space="preserve">
<value>The foreign keys {foreignKeyProperties1} on '{entityType1}' and {foreignKeyProperties2} on '{entityType2}' are both mapped to '{table}.{foreignKeyName}' but use different columns ({columnNames1} and {columnNames2}).</value>
Expand Down Expand Up @@ -362,13 +362,13 @@
<value>The specified entity type '{derivedType}' is not derived from '{entityType}'.</value>
</data>
<data name="InvalidKeySelectorForGroupBy" xml:space="preserve">
<value>The grouping key '{keySelector}' is of type '{keyType}' which is not valid key. </value>
<value>The grouping key '{keySelector}' is of type '{keyType}' which is not valid key.</value>
</data>
<data name="InvalidMappedFunctionDerivedType" xml:space="preserve">
<value>The entity type '{entityType}' is mapped to the DbFunction named '{functionName}' and it's derived from '{baseEntityType}'. Derived entity types cannot be mapped to a function.</value>
</data>
<data name="InvalidMappedFunctionUnmatchedReturn" xml:space="preserve">
<value>The entity type '{entityType}' is mapped to the DbFunction named '{functionName}' with return type '{returnType}'. Ensure that mapped function returns `IQueryable&lt;{clrType}&gt;`.</value>
<value>The entity type '{entityType}' is mapped to the DbFunction named '{functionName}' with return type '{returnType}'. Ensure that mapped function returns 'IQueryable&lt;{clrType}&gt;'.</value>
</data>
<data name="InvalidMappedFunctionWithParameters" xml:space="preserve">
<value>The entity type '{entityType}' is mapped to the DbFunction named '{functionName}' with parameters {parameters}. Ensure that mapped function doesn't have any parameters.</value>
Expand Down Expand Up @@ -514,7 +514,7 @@
<comment>Warning RelationalEventId.MigrationAttributeMissingWarning string</comment>
</data>
<data name="LogMultipleCollectionIncludeWarning" xml:space="preserve">
<value>Compiling a query which loads related collections for more than one collection navigation either via 'Include' or through projection but no 'QuerySplittingBehavior' has been configured. By default Entity Framework will use 'QuerySplittingBehavior.SingleQuery' which can potentially result in slow query performance. See https://go.microsoft.com/fwlink/?linkid=2134277 for more information. To identify the query that's triggering this warning call 'ConfigureWarnings(w =&gt; w.Throw(RelationalEventId.MultipleCollectionIncludeWarning))'</value>
<value>Compiling a query which loads related collections for more than one collection navigation either via 'Include' or through projection but no 'QuerySplittingBehavior' has been configured. By default Entity Framework will use 'QuerySplittingBehavior.SingleQuery' which can potentially result in slow query performance. See https://go.microsoft.com/fwlink/?linkid=2134277 for more information. To identify the query that's triggering this warning call 'ConfigureWarnings(w =&gt; w.Throw(RelationalEventId.MultipleCollectionIncludeWarning))'.</value>
<comment>Warning RelationalEventId.MultipleCollectionIncludeWarning</comment>
</data>
<data name="LogNamedIndexAllPropertiesNotToMappedToAnyTable" xml:space="preserve">
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/EFCore.SqlServer/Properties/SqlServerStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
<comment>Warning SqlServerEventId.DecimalTypeDefaultWarning string string</comment>
</data>
<data name="LogFoundColumn" xml:space="preserve">
<value>Found column with table: {tableName}, column name: {columnName}, ordinal: {ordinal}, data type: {dataType}, maximum length: {maxLength}, precision: {precision}, scale: {scale}, nullable: {nullable}, identity: {identity}, default value: {defaultValue}, computed value: {computedValue}, computed value is stored: {stored}</value>
<value>Found column with table: {tableName}, column name: {columnName}, ordinal: {ordinal}, data type: {dataType}, maximum length: {maxLength}, precision: {precision}, scale: {scale}, nullable: {nullable}, identity: {identity}, default value: {defaultValue}, computed value: {computedValue}, computed value is stored: {stored}.</value>
<comment>Debug SqlServerEventId.ColumnFound string string int string int int int bool bool string string bool?</comment>
</data>
<data name="LogFoundDefaultSchema" xml:space="preserve">
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/EFCore.Sqlite.NTS/Properties/SqliteNTSStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="InvalidGeometryType" xml:space="preserve">
<value>Invalid geometry type: {storeType}</value>
<value>Invalid geometry type: {storeType}.</value>
</data>
<data name="NTSServicesMissing" xml:space="preserve">
<value>UseNetTopologySuite requires AddEntityFrameworkSqliteNetTopologySuite to be called on the internal service provider used.</value>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/ChangeTracking/EntityEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public virtual EntityState State
if (value < 0
|| (int)value > _maxEntityState)
{
throw new ArgumentException(CoreStrings.InvalidEnumValue(nameof(value), typeof(EntityState)));
throw new ArgumentException(CoreStrings.InvalidEnumValue(value, nameof(value), typeof(EntityState)));
}

InternalEntry.SetEntityState(value);
Expand Down
12 changes: 9 additions & 3 deletions src/EFCore/Infrastructure/ModelValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,9 @@ protected virtual void ValidateNoCycles(

if (!reachableTypes.Add(principalType))
{
throw new InvalidOperationException(CoreStrings.IdentifyingRelationshipCycle(rootEntityType.DisplayName()));
throw new InvalidOperationException(CoreStrings.IdentifyingRelationshipCycle(
rootEntityType.DisplayName(),
primaryKey.Properties.Format()));
}

typesToValidate.Enqueue(principalType);
Expand Down Expand Up @@ -578,7 +580,8 @@ private void ValidateClrInheritance(
if (!baseEntityType.IsAssignableFrom(entityType))
{
throw new InvalidOperationException(
CoreStrings.InconsistentInheritance(entityType.DisplayName(), baseEntityType.DisplayName()));
CoreStrings.InconsistentInheritance(
entityType.DisplayName(), entityType.BaseType.DisplayName(), baseEntityType.DisplayName()));
}

break;
Expand Down Expand Up @@ -714,7 +717,10 @@ protected virtual void ValidateOwnership(
var ownerships = entityType.GetForeignKeys().Where(fk => fk.IsOwnership).ToList();
if (ownerships.Count > 1)
{
throw new InvalidOperationException(CoreStrings.MultipleOwnerships(entityType.DisplayName()));
throw new InvalidOperationException(CoreStrings.MultipleOwnerships(
entityType.DisplayName(),
string.Join(", ",
ownerships.Select(o => $"'{o.PrincipalEntityType.DisplayName()}.{o.PrincipalToDependent?.Name}'"))));
}

if (ownerships.Count == 1)
Expand Down
4 changes: 3 additions & 1 deletion src/EFCore/Internal/InternalDbSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ public override IEntityType EntityType

if (_entityType.IsOwned())
{
var message = CoreStrings.InvalidSetTypeOwned(
_entityType.DisplayName(), _entityType.FindOwnership().PrincipalEntityType.DisplayName());
_entityType = null;

throw new InvalidOperationException(CoreStrings.InvalidSetTypeOwned(typeof(TEntity).ShortDisplayName()));
throw new InvalidOperationException(message);
}

if (_entityType.ClrType != typeof(TEntity))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,10 @@ private static IReadOnlyList<string> FindCandidateDependentPropertiesThroughNavi
if (attribute?.Name == navigationFkAttribute.Name)
{
throw new InvalidOperationException(
CoreStrings.MultipleNavigationsSameFk(navigation.DeclaringEntityType.DisplayName(), attribute.Name));
CoreStrings.MultipleNavigationsSameFk(
navigation.DeclaringEntityType.DisplayName(),
attribute.Name,
$"'{navigation.Name}', '{propertyInfo.Name}'"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,8 @@ private IConventionForeignKeyBuilder ConfigureInverseNavigation(
{
throw new InvalidOperationException(
CoreStrings.SelfReferencingNavigationWithInverseProperty(
navigationMemberInfo.Name,
entityType.DisplayName(),
navigationMemberInfo.Name,
entityType.DisplayName()));
navigationMemberInfo.Name));
}

// Check for InversePropertyAttribute on the inverse navigation to verify that it matches.
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore/Metadata/Conventions/KeyAttributeConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ public virtual void ProcessModelFinalizing(
&& Attribute.IsDefined(memberInfo, typeof(KeyAttribute), inherit: true))
{
throw new InvalidOperationException(
CoreStrings.KeyAttributeOnDerivedEntity(entityType.DisplayName(), declaredProperty.Name));
CoreStrings.KeyAttributeOnDerivedEntity(
entityType.DisplayName(), declaredProperty.Name, entityType.GetRootType().DisplayName()));
}
}
}
Expand Down
Loading

0 comments on commit 19d6f7a

Please sign in to comment.