{"record":{"id":"5c43ed39a1641ca0","repo":"dotnet/efcore","slug":"the-object-name-has-been-removed-from-the-mode-5c43ed","errorCode":null,"errorMessage":"The object '{name}' has been removed from the model.","messagePattern":"The object '(.+?)' has been removed from the model\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Metadata/Internal/StoredProcedure.cs","lineNumber":62,"sourceCode":"    {\n        EntityType = entityType;\n        _configurationSource = configurationSource;\n        _builder = new InternalStoredProcedureBuilder(this, ((IConventionEntityType)entityType).Model.Builder);\n    }\n\n    /// <inheritdoc />\n    public virtual IMutableEntityType EntityType { get; set; }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual InternalStoredProcedureBuilder Builder\n    {\n        [DebuggerStepThrough]\n        get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(Name));\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual bool IsInModel\n        => _builder is not null;\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual void SetRemovedFromModel()","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Metadata/Internal/StoredProcedure.cs#L44-L80","documentation":"Thrown when accessing the Builder of an InternalStoredProcedure after the stored procedure mapping has been removed from the model. The _builder field is null once detached.","triggerScenarios":"InternalStoredProcedureBuilder.Builder get when _builder is null. Triggered by retaining a stored procedure builder reference after the mapping was removed (entity ignored, mapping cleared, model rebuild) and then re-accessing Builder.","commonSituations":"Conventions or model configurators caching a stored procedure builder across mutations; calling configuration twice after an intervening removal; tests mutating the model and reusing handles.","solutions":["Check IsInModel before accessing Builder.","Do not cache stored procedure builder references across mutations; re-resolve via EntityType.FindStoredProcedure.","Make sure the entity still has the stored procedure mapping before reconfiguring.","Rebuild the model rather than reusing detached metadata."],"exampleFix":"// before\nvar sprocBuilder = entityTypeBuilder.Metadata.FindUpdateStoredProcedure()!.Builder;\nentityTypeBuilder.Metadata.RemoveStoredProcedure();\nsprocBuilder.HasParameter(...); // throws\n\n// after\nif (sprocBuilder.IsInModel)\n{\n    sprocBuilder.HasParameter(...);\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static bool StoredProcedureIsLive(IConventionStoredProcedure sproc)\n    => sproc is { IsInModel: true };","tryCatchPattern":null,"preventionTips":["Check IsInModel before accessing Builder on a stored procedure mapping.","Re-resolve stored procedures via EntityType.FindStoredProcedure instead of caching handles.","Avoid removing the mapping while a convention is mid-flight.","Rebuild the model when reconfiguring rather than reusing detached metadata."],"tags":["ef-core","relational-metadata","stored-procedure","object-lifecycle","internal-api"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}