Skip to content

Commit

Permalink
Improve some exception messages.
Browse files Browse the repository at this point in the history
Fixes #28852
Fixes #27705
Fixes #25346
  • Loading branch information
AndriySvyryd committed Nov 8, 2023
1 parent 684b1be commit 8e35002
Show file tree
Hide file tree
Showing 24 changed files with 42 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Metadata/Internal/CheckConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public static bool AreCompatible(
public virtual InternalCheckConstraintBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(ModelName));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Metadata/Internal/DbFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static string GetFunctionName(MethodInfo methodInfo)
public virtual InternalDbFunctionBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(ModelName));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public DbFunctionParameter(
public virtual InternalDbFunctionParameterBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(Name));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public EntityTypeMappingFragment(
public virtual InternalEntityTypeMappingFragmentBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(
StoreObject.DisplayName()));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public override bool IsReadOnly
public virtual InternalRelationalPropertyOverridesBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(
$"{Property.Name} - {StoreObject.DisplayName()}"));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Metadata/Internal/Sequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public static Sequence AddSequence(
public virtual InternalSequenceBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(Name));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Metadata/Internal/StoredProcedure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public StoredProcedure(
public virtual InternalStoredProcedureBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(Name));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public StoredProcedureParameter(
public virtual InternalStoredProcedureParameterBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(Name));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public StoredProcedureResultColumn(
public virtual InternalStoredProcedureResultColumnBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(Name));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.EntityFrameworkCore.Storage;
/// See <see href="https://aka.ms/efcore-docs-providers">Implementation of database providers and extensions</see>
/// for more information and examples.
/// </remarks>
public readonly struct RelationalCommandParameterObject
public readonly record struct RelationalCommandParameterObject
{
/// <summary>
/// <para>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Internal/ComplexProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ComplexProperty(
public virtual InternalComplexPropertyBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(Name));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Internal/ComplexType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public ComplexType(
public new virtual InternalComplexTypeBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(Name));
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore/Metadata/Internal/ElementType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Xml.Linq;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Storage.Json;
Expand Down Expand Up @@ -80,7 +81,7 @@ public virtual void SetConfigurationSource(ConfigurationSource configurationSour
public virtual InternalElementTypeBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(ClrType.ShortDisplayName()));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Internal/EntityType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public EntityType(
public new virtual InternalEntityTypeBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(DisplayName()));
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore/Metadata/Internal/ForeignKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public ForeignKey(
public virtual InternalForeignKeyBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(
Property.Format(Properties.Select(p => p.Name))));
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore/Metadata/Internal/Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public Index(
public virtual InternalIndexBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(
Property.Format(Properties.Select(p => p.Name))));
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore/Metadata/Internal/Key.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public virtual EntityType DeclaringEntityType
public virtual InternalKeyBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(
Property.Format(Properties.Select(p => p.Name))));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Internal/Navigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public virtual object? Sentinel
public virtual InternalNavigationBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(Name));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Internal/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Property(
public virtual InternalPropertyBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(Name));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Internal/ServiceProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public override TypeBase DeclaringType
public virtual InternalServicePropertyBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(Name));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Internal/SkipNavigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public override Type ClrType
public virtual InternalSkipNavigationBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(Name));
}

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion src/EFCore/Metadata/Internal/Trigger.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Xml.Linq;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal;

/// <summary>
Expand Down Expand Up @@ -42,7 +44,7 @@ public Trigger(
public virtual InternalTriggerBuilder Builder
{
[DebuggerStepThrough]
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel);
get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(ModelName));
}

/// <summary>
Expand Down
14 changes: 8 additions & 6 deletions src/EFCore/Properties/CoreStrings.Designer.cs

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

8 changes: 4 additions & 4 deletions src/EFCore/Properties/CoreStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
<value>The [{attribute}] attribute may only be specified on entity type properties. Remove the attribute from '{type}.{propertyName}'.</value>
</data>
<data name="AutoIncludeNavigationCycle" xml:space="preserve">
<value>Cycle detected while auto-including navigations: {cycleNavigations}. To fix this issue, either don't configure at least one navigation in the cycle as auto included in `OnModelCreating` or call 'IgnoreAutoInclude' method on the query.</value>
<value>Cycle detected while auto-including navigations: {cycleNavigations}. To fix this issue, either don't configure at least one navigation in the cycle as auto included in 'OnModelCreating' or call 'IgnoreAutoInclude' method on the query.</value>
</data>
<data name="BackingFieldOnIndexer" xml:space="preserve">
<value>Cannot set backing field '{field}' for the indexer property '{entityType}.{property}'. Ensure no backing fields are specified for indexer properties.</value>
Expand Down Expand Up @@ -256,7 +256,7 @@
<value>The entity type '{entityType}' cannot be marked as owned because the derived entity type '{derivedType}' has been configured as non-owned. Either don't configure '{derivedType}' as non-owned, or call 'HasBaseType(null)' for it in 'OnModelCreating'. See https://aka.ms/efcore-docs-owned for more information and examples.</value>
</data>
<data name="ClashingNonOwnedEntityType" xml:space="preserve">
<value>The entity type '{entityType}' cannot be configured as owned because it has already been configured as a non-owned. If you want to override previous configuration first remove the entity type from the model by calling 'Ignore'. See https://aka.ms/efcore-docs-owned for more information and examples.</value>
<value>The entity type '{entityType}' cannot be configured as owned because it has already been configured as a non-owned. If the entity type should be owned remove the 'Entity&lt;{entityType}&gt;()' call if possible, or otherwise remove the entity type from the model by calling 'Ignore'. See https://aka.ms/efcore-docs-owned for more information and examples.</value>
</data>
<data name="ClashingNonSharedType" xml:space="preserve">
<value>The shared-type entity type '{entityType}' with CLR type '{type}' cannot be added to the model because a non-shared entity type with the same CLR type already exists.</value>
Expand All @@ -265,7 +265,7 @@
<value>The entity type '{entityType}' cannot be marked as non-owned because the derived entity type '{derivedType}' has been configured as owned. Either don't configure '{derivedType}' as owned, or call 'HasBaseType(null)' for it in 'OnModelCreating'. See https://aka.ms/efcore-docs-owned for more information and examples.</value>
</data>
<data name="ClashingOwnedEntityType" xml:space="preserve">
<value>The entity type '{entityType}' cannot be configured as non-owned because it has already been configured as a owned. Use the nested builder in `OwnsOne` or `OwnsMany` on the owner entity type builder to further configure this type. If you want to override previous configuration first remove the entity type from the model by calling 'Ignore'. See https://aka.ms/efcore-docs-owned for more information and examples.</value>
<value>The entity type '{entityType}' cannot be configured as non-owned because it has already been configured as a owned. Use the nested builder in 'OwnsOne' or 'OwnsMany' on the owner entity type builder to further configure this type. If the entity type shouldn't be owned and you are unable to remove the 'OwnsOne' or 'OwnsMany' call you can remove the entity type from the model by calling 'Ignore'. See https://aka.ms/efcore-docs-owned for more information and examples.</value>
</data>
<data name="ClashingSharedType" xml:space="preserve">
<value>The entity type '{entityType}' cannot be added to the model because its CLR type has been configured as a shared type.</value>
Expand Down Expand Up @@ -1256,7 +1256,7 @@
<value>The primitive collection property '{type}.{property}' is configured as required (non-nullable) but has a null value when saving changes. Either mark the property as optional (nullable) or set a non-null value.</value>
</data>
<data name="ObjectRemovedFromModel" xml:space="preserve">
<value>The object has been removed from the model.</value>
<value>The object '{name}' has been removed from the model.</value>
</data>
<data name="OptionsExtensionNotFound" xml:space="preserve">
<value>Options extension of type '{optionsExtension}' not found.</value>
Expand Down

0 comments on commit 8e35002

Please sign in to comment.