{"record":{"id":"85a406c62b9688af","repo":"dotnet/efcore","slug":"the-requested-configuration-is-not-stored-in-the-r-85a406","errorCode":null,"errorMessage":"The requested configuration is not stored in the read-optimized model, please use 'DbContext.GetService<IDesignTimeModel>().Model'.","messagePattern":"The requested configuration is not stored in the read-optimized model, please use 'DbContext\\.GetService<IDesignTimeModel>\\(\\)\\.Model'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs","lineNumber":966,"sourceCode":"    ///     It is useful when iterating over all entity types to avoid processing the same check constraint more than once.\n    ///     Use <see cref=\"GetCheckConstraints(IEntityType)\" /> to also return check constraints declared on base types.\n    /// </remarks>\n    /// <param name=\"entityType\">The entity type to get the check constraints for.</param>\n    public static IEnumerable<ICheckConstraint> GetDeclaredCheckConstraints(this IEntityType entityType)\n        => CheckConstraint.GetDeclaredCheckConstraints(entityType).Cast<ICheckConstraint>();\n\n    #endregion Check constraint\n\n    #region Comment\n\n    /// <summary>\n    ///     Returns the comment for the table this entity is mapped to.\n    /// </summary>\n    /// <param name=\"entityType\">The entity type.</param>\n    /// <returns>The comment for the table this entity is mapped to.</returns>\n    public static string? GetComment(this IReadOnlyEntityType entityType)\n        => (entityType is RuntimeEntityType)\n            ? throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData)\n            : (string?)entityType[RelationalAnnotationNames.Comment];\n\n    /// <summary>\n    ///     Configures a comment to be applied to the table this entity is mapped to.\n    /// </summary>\n    /// <param name=\"entityType\">The entity type.</param>\n    /// <param name=\"comment\">The comment for the table this entity is mapped to.</param>\n    public static void SetComment(this IMutableEntityType entityType, string? comment)\n        => entityType.SetOrRemoveAnnotation(RelationalAnnotationNames.Comment, comment);\n\n    /// <summary>\n    ///     Configures a comment to be applied to the table this entity is mapped to.\n    /// </summary>\n    /// <param name=\"entityType\">The entity type.</param>\n    /// <param name=\"comment\">The comment for the table.</param>\n    /// <param name=\"fromDataAnnotation\">Indicates whether the configuration was specified using a data annotation.</param>\n    /// <returns>The configured comment.</returns>\n    public static string? SetComment(","sourceCodeStart":948,"sourceCodeEnd":984,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs#L948-L984","documentation":"GetComment() reads the RelationalComment annotation from an entity type. The read-optimized runtime model (RuntimeEntityType) intentionally strips design-time-only configuration such as table comments. The method explicitly checks for RuntimeEntityType and throws to redirect you to the design-time model, which retains these annotations.","triggerScenarios":"Calling entityType.GetComment() where entityType is a RuntimeEntityType instance — typically obtained from the runtime IModel (DbContext.Model at runtime) rather than the design-time model.","commonSituations":"Custom migrations or scaffolding code that iterates DbContext.Model (runtime) instead of IDesignTimeModel; conventions or tools reading comments at runtime; shared code paths that receive either model kind.","solutions":["Obtain the design-time model via DbContext.GetService<IDesignTimeModel>().Model and call GetComment on its entity types.","Keep design-time-only annotation reads out of runtime code paths.","Add an is RuntimeEntityType guard at the call site to choose the correct model source."],"exampleFix":"// before\nvar comment = ctx.Model.GetEntityTypes().First().GetComment();\n// after\nvar dtm = ctx.GetService<IDesignTimeModel>().Model;\nvar comment = dtm.GetEntityTypes().First().GetComment();","handlingStrategy":"type-guard","validationCode":"// Use the design-time model whenever you need table comments.\nIModel model = ctx.GetService<IDesignTimeModel>().Model;\nvar comment = entityTypeFromDesignTimeModel.GetComment();","typeGuard":"using Microsoft.EntityFrameworkCore.Metadata.Internal;\nstatic bool IsRuntime(IEntityType et) => et is RuntimeEntityType;\nstatic string? SafeGetComment(IEntityType et)\n    => et is RuntimeEntityType ? null : et.GetComment();","tryCatchPattern":"try { return entityType.GetComment(); }\ncatch (InvalidOperationException) when (entityType is RuntimeEntityType)\n{ /* fall back to IDesignTimeModel */ }","preventionTips":["Always source design-time annotations from IDesignTimeModel.","Tag helper parameters with the design-time model type to prevent runtime-model leakage.","Write an assertion that no RuntimeEntityType reaches annotation-reading code."],"tags":["runtime-model","design-time","annotations","comments","entity-type"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}