dotnet/efcore · error · InvalidOperationException
The object ' ' has been removed from the model.
Error message
The object '{name}' has been removed from the model. What it means
Thrown when accessing the Builder of an InternalRelationalPropertyOverrides instance after it (or its property) has been removed from the model. Once removed, the overrides object holds a null _builder and the Builder getter refuses to return it.
Solutions
- Check IsInModel before accessing Builder.
- Do not cache overrides builders across model mutations; re-fetch them each time.
- Ensure the property is still mapped (not Ignored) before reconfiguring its overrides.
- Rebuild the model fresh instead of reusing removed metadata objects.
Example fix
// before
var overridesBuilder = propertyBuilder.Metadata.GetOverrides(storeObject);
// ... later, after the property is ignored
overridesBuilder.Builder.Property.HasColumn(...); // throws
// after
if (overridesBuilder.IsInModel)
{
overridesBuilder.Builder.Property.HasColumn(...);
} Defensive patterns
Strategy: type-guard
Type guard
// Guard before touching the overrides builder.
static bool OverridesAreLive(InternalRelationalPropertyOverrides overrides)
=> overrides is { IsInModel: true }; Prevention
- Check IsInModel before accessing Builder on any internal overrides object.
- Never cache overrides builders across model mutations.
- Re-fetch metadata objects after Ignore/Remove operations.
- Prefer the convention API over direct internal-builder use.
When it happens
Trigger: InternalRelationalPropertyOverridesBuilder.Builder get when _builder is null. Triggered by holding a reference to an overrides builder obtained before the property/overrides were removed (e.g. via Ignore, RemoveProperty, or clearing relational overrides), then later touching its Builder.
Common situations: Long-lived conventions or model customizers caching an overrides builder across mutation steps; calling configuration code twice where the second call runs after the property was ignored; model caching where a stale builder reference survives a model rebuild.
Related errors
- The object ' ' has been removed from the model.
- The object ' ' has been removed from the model.
- Invalid type for sequence. Valid types are 'long' (the…
- The foreign keys on ' ' and on ' ' are both mapped to ' …
- The foreign keys on ' ' and on ' ' are both mapped to ' …
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/90e2e1a18158eebb.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Relational/Metadata/Internal/RelationalPropertyOverrides.cs:77
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override bool IsReadOnly
=> ((Annotatable)Property).IsReadOnly;
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual InternalRelationalPropertyOverridesBuilder Builder
{
[DebuggerStepThrough]
get => _builder
?? throw new InvalidOperationException(
CoreStrings.ObjectRemovedFromModel(
$"{Property.Name} - {StoreObject.DisplayName()}"));
}
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual bool IsInModel
=> _builder is not null
&& ((IConventionAnnotatable)Property).IsInModel;
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing thatView on GitHub (pinned to 3a2006ef56)