{"record":{"id":"6be2176efa87e195","repo":"dotnet/efcore","slug":"the-requested-configuration-is-not-stored-in-the-r-6be217","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/RelationalModelExtensions.cs","lineNumber":499,"sourceCode":"    /// <summary>\n    ///     Returns all functions contained in the model.\n    /// </summary>\n    /// <param name=\"model\">The model to get the functions in.</param>\n    public static IEnumerable<IDbFunction> GetDbFunctions(this IModel model)\n        => DbFunction.GetDbFunctions(model);\n\n    #endregion DbFunction\n\n    #region Collation\n\n    /// <summary>\n    ///     Returns the database collation.\n    /// </summary>\n    /// <param name=\"model\">The model to get the collation for.</param>\n    /// <returns>The collation.</returns>\n    public static string? GetCollation(this IReadOnlyModel model)\n        => (model is RuntimeModel)\n            ? throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData)\n            : (string?)model[RelationalAnnotationNames.Collation];\n\n    /// <summary>\n    ///     Sets the database collation.\n    /// </summary>\n    /// <param name=\"model\">The model to set the collation for.</param>\n    /// <param name=\"value\">The value to set.</param>\n    public static void SetCollation(this IMutableModel model, string? value)\n        => model.SetOrRemoveAnnotation(\n            RelationalAnnotationNames.Collation,\n            Check.NullButNotEmpty(value));\n\n    /// <summary>\n    ///     Sets the database collation.\n    /// </summary>\n    /// <param name=\"model\">The model to set the collation for.</param>\n    /// <param name=\"value\">The value to set.</param>\n    /// <param name=\"fromDataAnnotation\">Indicates whether the configuration was specified using a data annotation.</param>","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs#L481-L517","documentation":"IReadOnlyModel.GetCollation() throws CoreStrings.RuntimeModelMissingData on a RuntimeModel, because the database collation annotation is design-time only (RelationalModelExtensions.cs:499). The runtime model is optimized and omits collation metadata.","triggerScenarios":"Calling dbContext.Model.GetCollation() (runtime model) instead of the design-time model's GetCollation().","commonSituations":"Diagnostic or logging code that reports the configured collation at runtime; sharing metadata-reading code across runtime and design-time paths.","solutions":["Read collation from the design-time model: dbContext.GetService<IDesignTimeModel>().Model.GetCollation().","Keep collation-related introspection in migrations/scaffolding code that operates on the design-time model."],"exampleFix":"// before\nvar coll = dbContext.Model.GetCollation();   // throws\n\n// after\nvar coll = dbContext.GetService<IDesignTimeModel>().Model.GetCollation();","handlingStrategy":"validation","validationCode":"var coll = dbContext.GetService<IDesignTimeModel>().Model.GetCollation();","typeGuard":"static bool IsDesignTime(IModel m) => m is not RuntimeModel;","tryCatchPattern":null,"preventionTips":["Route collation reads through IDesignTimeModel.","Do not expose collation metadata in runtime app code."],"tags":["runtime-model","design-time-model","metadata","collation"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}