{"record":{"id":"ec4d34060ba00876","repo":"dotnet/efcore","slug":"the-requested-configuration-is-not-stored-in-the-r-ec4d34","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/Metadata/Internal/Table.cs","lineNumber":222,"sourceCode":"    IEnumerable<IUniqueConstraint> ITable.UniqueConstraints\n    {\n        [DebuggerStepThrough]\n        get => UniqueConstraints.Values;\n    }\n\n    /// <inheritdoc />\n    IEnumerable<ITableIndex> ITable.Indexes\n    {\n        [DebuggerStepThrough]\n        get => Indexes.Values;\n    }\n\n    /// <inheritdoc />\n    IEnumerable<ICheckConstraint> ITable.CheckConstraints\n    {\n        [DebuggerStepThrough]\n        get => EntityTypeMappings.First().TypeBase is RuntimeEntityType\n            ? throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData)\n            : CheckConstraints.Values;\n    }\n\n    /// <inheritdoc />\n    IEnumerable<ITrigger> ITable.Triggers\n    {\n        [DebuggerStepThrough]\n        get => Triggers.Values;\n    }\n\n    /// <inheritdoc />\n    [DebuggerStepThrough]\n    IColumn? ITable.FindColumn(string name)\n        => (IColumn?)base.FindColumn(name);\n\n    /// <inheritdoc />\n    [DebuggerStepThrough]\n    IColumn? ITable.FindColumn(IPropertyBase propertyBase)","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Metadata/Internal/Table.cs#L204-L240","documentation":"The read-optimized runtime model omits design-time-only data such as check constraints. When the underlying EntityType is a RuntimeEntityType, the Table.CheckConstraints getter throws, directing you to the design-time model where that metadata lives.","triggerScenarios":"Calling table.CheckConstraints (via the ITable interface) on a Table built from a runtime/read-optimized model (e.g. the model returned by DbContext.Model after the context is finalized, or under NativeAOT compiled models).","commonSituations":"Tooling, migrations, or scaffolding code that accidentally uses the runtime Model instead of IDesignTimeModel; switching a project to NativeAOT/compiled models; querying check constraints at runtime in a hot path.","solutions":["Resolve the design-time model: DbContext.GetService<IDesignTimeModel>().Model, and read CheckConstraints from its tables.","Move check-constraint inspection out of runtime code paths into design-time tooling.","Cache the design-time model once for the application lifetime when tooling needs it.","Confirm you are not passing a RuntimeModel where a convention model is expected."],"exampleFix":"// before\nvar table = dbContext.Model.GetTables().First();\nvar checks = ((ITable)table).CheckConstraints; // throws in runtime model\n\n// after\nvar designModel = dbContext.GetService<IDesignTimeModel>().Model;\nvar table = designModel.GetTables().First();\nvar checks = ((ITable)table).CheckConstraints;","handlingStrategy":"validation","validationCode":"// Use the design-time model for check-constraint inspection.\nvar designModel = dbContext.GetService<IDesignTimeModel>().Model;\nvar table = designModel.GetTables().First(t => t.Name == \"Orders\");\nvar checks = ((ITable)table).CheckConstraints;","typeGuard":"static bool IsDesignTimeModel(IModel model)\n    => model is not RuntimeModel;","tryCatchPattern":null,"preventionTips":["Reserve check-constraint (and other design-time) inspection for IDesignTimeModel-based tooling.","Keep runtime code paths off ITable.CheckConstraints.","Under NativeAOT, always pair the app with a compiled model and verify tooling uses the design-time model."],"tags":["ef-core","runtime-model","design-time","native-aot","check-constraints"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}