dotnet/efcore · error · InvalidOperationException

The requested configuration is not stored in the…

Error message

The requested configuration is not stored in the read-optimized model, please use 'DbContext.GetService<IDesignTimeModel>().Model'.

What it means

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.

Solutions

  1. Obtain the design-time model via IDesignTimeModel and read column order from its properties.
  2. Guard with 'is RuntimeProperty' and branch accordingly.
  3. Keep column-order reads inside design-time-only code.

Example fix

// before
var order = ctx.Model.GetEntityTypes().First().GetProperties().First().GetColumnOrder();
// after
var dtm = ctx.GetService<IDesignTimeModel>().Model;
var order = dtm.GetEntityTypes().First().GetProperties().First().GetColumnOrder();
Defensive patterns

Strategy: type-guard

Validate before calling

IModel model = ctx.GetService<IDesignTimeModel>().Model;
var order = propFromDesignTimeModel.GetColumnOrder();

Type guard

using Microsoft.EntityFrameworkCore.Metadata.Internal;
static bool IsRuntime(IProperty p) => p is RuntimeProperty;
static int? SafeGetColumnOrder(IProperty p)
    => p is RuntimeProperty ? null : p.GetColumnOrder();

Try / catch

try { return property.GetColumnOrder(); }
catch (InvalidOperationException) when (property is RuntimeProperty)
{ return null; }

Prevention

When it happens

Trigger: Calling property.GetColumnOrder() on a RuntimeProperty obtained from the runtime model at query time rather than the design-time model.

Common situations: Migration or scaffolding code bound to the runtime IModel; shared utilities that receive either model kind; tooling inspecting column ordering at runtime.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/7c8c40dda63f2b2c. Report an issue: GitHub.

Appendix: source

Thrown at src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs:396

    /// <summary>
    ///     Gets the <see cref="ConfigurationSource" /> for the column name for a particular table-like store object.
    /// </summary>
    /// <param name="property">The property.</param>
    /// <param name="storeObject">The identifier of the table-like store object containing the column.</param>
    /// <returns>The <see cref="ConfigurationSource" /> for the column name for a particular table-like store object.</returns>
    public static ConfigurationSource? GetColumnNameConfigurationSource(
        this IConventionProperty property,
        in StoreObjectIdentifier storeObject)
        => property.FindOverrides(storeObject)?.GetColumnNameConfigurationSource();

    /// <summary>
    ///     Returns the order of the column this property is mapped to.
    /// </summary>
    /// <param name="property">The property.</param>
    /// <returns>The column order.</returns>
    public static int? GetColumnOrder(this IReadOnlyProperty property)
        => (property is RuntimeProperty)
            ? throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData)
            : (int?)property.FindAnnotation(RelationalAnnotationNames.ColumnOrder)?.Value;

    /// <summary>
    ///     Returns the order of the column this property is mapped to for a particular table.
    /// </summary>
    /// <param name="property">The property.</param>
    /// <param name="storeObject">The identifier of the table-like store object containing the column.</param>
    /// <returns>The column order.</returns>
    public static int? GetColumnOrder(this IReadOnlyProperty property, in StoreObjectIdentifier storeObject)
    {
        if (property is RuntimeProperty)
        {
            throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData);
        }

        var annotation = property.FindAnnotation(RelationalAnnotationNames.ColumnOrder);
        if (annotation != null)
        {

View on GitHub (pinned to 3a2006ef56)