{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs#L948-L984","documentation":"IEntityType.GetComment() reads a design-time-only annotation (RelationalAnnotationNames.Comment) that is stripped from the read-optimized runtime model. When the instance is a RuntimeEntityType, EF throws CoreStrings.RuntimeModelMissingData (RelationalEntityTypeExtensions.cs:966). Use the design-time model to read table comments.","triggerScenarios":"Calling entityType.GetComment() where entityType was obtained from DbContext.Model (the runtime IModel) instead of from the design-time model.","commonSituations":"Writing a migration/annotation tool, a code generator, or a test that reads comments from context.Model.GetEntityTypes() at runtime; mixing design-time metadata accessors with runtime model traversal.","solutions":["Resolve the design-time model: dbContext.GetService<IDesignTimeModel>().Model and read GetComment() from its entity types.","Restrict these metadata reads to design time (migrations, scaffolding) rather than runtime application code."],"exampleFix":"// before\nvar comment = dbContext.Model.GetEntityTypes()\n    .First().GetComment();   // throws: runtime model\n\n// after\nvar designModel = dbContext.GetService<IDesignTimeModel>().Model;\nvar comment = designModel.GetEntityTypes()\n    .First().GetComment();","handlingStrategy":"validation","validationCode":"// Resolve design-time model before reading design-time-only metadata.\nvar model = dbContext.GetService<IDesignTimeModel>().Model;\nforeach (var et in model.GetEntityTypes())\n{\n    var comment = et.GetComment(); // safe\n}","typeGuard":"static bool IsDesignTime(IEntityType et) => et is not RuntimeEntityType;","tryCatchPattern":null,"preventionTips":["Never read GetComment from dbContext.Model at runtime; use IDesignTimeModel.","Build a helper that always routes design-time metadata reads through IDesignTimeModel.","Tag runtime-vs-design-time metadata accessors in your codebase to prevent misuse."],"tags":["runtime-model","design-time-model","metadata","comment"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}