{"record":{"id":"64d1d043a17eeb6f","repo":"dotnet/efcore","slug":"the-object-name-has-been-removed-from-the-mode-64d1d0","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/Sequence.cs","lineNumber":236,"sourceCode":"        }\n\n        var mutableSequence = (Sequence)sequence;\n        sequences.Remove((name, schema));\n        mutableSequence.SetRemovedFromModel();\n\n        return mutableSequence;\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 InternalSequenceBuilder 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":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Metadata/Internal/Sequence.cs#L218-L254","documentation":"Thrown when accessing the Builder of an InternalSequence after it (or its model) has been removed. The Sequence retains its name for the message but its _builder is null once detached.","triggerScenarios":"InternalSequenceBuilder.Builder get when _builder is null. Triggered by holding an InternalSequence reference after the sequence was removed from the model (model.RemoveSequence, Ignore, or model finalization that drops it) and then accessing its Builder.","commonSituations":"Convention or pre-validation code caching a sequence builder; HasSequence invoked twice with intervening removal; model caching scenarios where the sequence is dropped but a reference persists; tests that mutate the model and reuse handles.","solutions":["Check IsInModel on the sequence before accessing Builder.","Do not retain sequence builder references across model mutations; re-resolve via model.FindSequence.","Avoid removing a sequence while a convention is mid-flight against it.","Recreate the model instead of reusing detached metadata."],"exampleFix":"// before\nvar seq = modelBuilder.HasSequence<long>(\"OrderSeq\");\nmodelBuilder.Ignore(\"OrderSeq\");\nseq.Builder.IncrementsBy(1); // throws\n\n// after\nif (seq.IsInModel)\n{\n    seq.Builder.IncrementsBy(1);\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static bool SequenceIsLive(ISequence sequence)\n    => sequence is IConventionSequence { IsInModel: true };","tryCatchPattern":null,"preventionTips":["Check IsInModel before accessing Builder on a sequence.","Re-resolve sequences via model.FindSequence instead of caching handles.","Avoid removing a sequence while a convention is operating on it.","Use a fresh model when reconfiguring."],"tags":["ef-core","relational-metadata","sequence","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"}