{"record":{"id":"7c8c40dda63f2b2c","repo":"dotnet/efcore","slug":"the-requested-configuration-is-not-stored-in-the-r-7c8c40","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/RelationalPropertyExtensions.cs","lineNumber":396,"sourceCode":"    /// <summary>\n    ///     Gets the <see cref=\"ConfigurationSource\" /> for the column name for a particular table-like store object.\n    /// </summary>\n    /// <param name=\"property\">The property.</param>\n    /// <param name=\"storeObject\">The identifier of the table-like store object containing the column.</param>\n    /// <returns>The <see cref=\"ConfigurationSource\" /> for the column name for a particular table-like store object.</returns>\n    public static ConfigurationSource? GetColumnNameConfigurationSource(\n        this IConventionProperty property,\n        in StoreObjectIdentifier storeObject)\n        => property.FindOverrides(storeObject)?.GetColumnNameConfigurationSource();\n\n    /// <summary>\n    ///     Returns the order of the column this property is mapped to.\n    /// </summary>\n    /// <param name=\"property\">The property.</param>\n    /// <returns>The column order.</returns>\n    public static int? GetColumnOrder(this IReadOnlyProperty property)\n        => (property is RuntimeProperty)\n            ? throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData)\n            : (int?)property.FindAnnotation(RelationalAnnotationNames.ColumnOrder)?.Value;\n\n    /// <summary>\n    ///     Returns the order of the column this property is mapped to for a particular table.\n    /// </summary>\n    /// <param name=\"property\">The property.</param>\n    /// <param name=\"storeObject\">The identifier of the table-like store object containing the column.</param>\n    /// <returns>The column order.</returns>\n    public static int? GetColumnOrder(this IReadOnlyProperty property, in StoreObjectIdentifier storeObject)\n    {\n        if (property is RuntimeProperty)\n        {\n            throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData);\n        }\n\n        var annotation = property.FindAnnotation(RelationalAnnotationNames.ColumnOrder);\n        if (annotation != null)\n        {","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs#L378-L414","documentation":"GetColumnOrder() reads the ColumnOrder annotation from a property. The read-optimized runtime model (RuntimeProperty) strips this design-time-only value, so the method throws to prevent returning an incorrect null/default and directs you to the design-time model.","triggerScenarios":"Calling property.GetColumnOrder() on a RuntimeProperty obtained from the runtime model at query time rather than the design-time model.","commonSituations":"Migration or scaffolding code bound to the runtime IModel; shared utilities that receive either model kind; tooling inspecting column ordering at runtime.","solutions":["Obtain the design-time model via IDesignTimeModel and read column order from its properties.","Guard with 'is RuntimeProperty' and branch accordingly.","Keep column-order reads inside design-time-only code."],"exampleFix":"// before\nvar order = ctx.Model.GetEntityTypes().First().GetProperties().First().GetColumnOrder();\n// after\nvar dtm = ctx.GetService<IDesignTimeModel>().Model;\nvar order = dtm.GetEntityTypes().First().GetProperties().First().GetColumnOrder();","handlingStrategy":"type-guard","validationCode":"IModel model = ctx.GetService<IDesignTimeModel>().Model;\nvar order = propFromDesignTimeModel.GetColumnOrder();","typeGuard":"using Microsoft.EntityFrameworkCore.Metadata.Internal;\nstatic bool IsRuntime(IProperty p) => p is RuntimeProperty;\nstatic int? SafeGetColumnOrder(IProperty p)\n    => p is RuntimeProperty ? null : p.GetColumnOrder();","tryCatchPattern":"try { return property.GetColumnOrder(); }\ncatch (InvalidOperationException) when (property is RuntimeProperty)\n{ return null; }","preventionTips":["Read column order from IDesignTimeModel only.","Guard shared helpers with a RuntimeProperty check.","Centralize design-time-only reads."],"tags":["runtime-model","design-time","annotations","column-order","property"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}