dotnet/efcore · error · InvalidOperationException

The property '{property}' on entity type '{entityType}' is n

Error message

The property '{property}' on entity type '{entityType}' is not mapped to '{table}'.

What it means

FindSharedStoreObjectRootProperty throws RelationalStrings.PropertyNotMappedToTable when property.GetColumnName(storeObject) returns null — the property is not mapped to a column on that store object (RelationalPropertyExtensions.cs:1534). This happens in table splitting / TPT / view scenarios where the property belongs to a different table than the one queried.

Source

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

    /// <returns>The property found, or <see langword="null" /> if none was found.</returns>
    public static IProperty? FindSharedStoreObjectRootProperty(
        this IProperty property,
        in StoreObjectIdentifier storeObject)
        => (IProperty?)FindSharedObjectRootProperty(property, storeObject);

    private static IReadOnlyProperty? FindSharedObjectRootProperty(IReadOnlyProperty property, in StoreObjectIdentifier storeObject)
    {
        if (property.DeclaringType.IsMappedToJson())
        {
            //JSON-splitting is not supported
            //Issue #28574
            return null;
        }

        var column = property.GetColumnName(storeObject);
        if (column == null)
        {
            throw new InvalidOperationException(
                RelationalStrings.PropertyNotMappedToTable(
                    property.Name, property.DeclaringType.DisplayName(), storeObject.DisplayName()));
        }

        var rootProperty = property;

        // Limit traversal to avoid getting stuck in a cycle (validation will throw for these later)
        // Using a hashset is detrimental to the perf when there are no cycles
        for (var i = 0; i < Metadata.Internal.RelationalEntityTypeExtensions.MaxEntityTypesSharingTable; i++)
        {
            var entityType = rootProperty.DeclaringType.ContainingEntityType;
            IReadOnlyProperty? linkedProperty = null;
            foreach (var principalProperty in entityType
                         .FindRowInternalForeignKeys(storeObject)
                         .SelectMany(static fk => fk.PrincipalEntityType.GetProperties()))
            {
                if (principalProperty.GetColumnName(storeObject) == column)
                {

View on GitHub (pinned to dbf9771522)

Solutions

  1. Guard the lookup: check property.GetColumnName(storeObject) != null before calling the shared-root lookup, or only pass store objects returned by StoreObjectIdentifier.Create(property.DeclaringType.ContainingEntityType, ...).
  2. Resolve the property against the entity type that actually owns the column (use the declaring/derived type for the store object).
  3. For JSON-mapped owned entities, note that JSON splitting is unsupported and returns null earlier — restructure to query the owning table.

Example fix

// before
var so = StoreObjectIdentifier.Table("OrderDetails", "dbo");
var root = orderProperty.FindSharedStoreObjectRootProperty(so); // Order.Id not on OrderDetails

// after
if (orderProperty.GetColumnName(so) is not null)
{
    var root = orderProperty.FindSharedStoreObjectRootProperty(so);
}
Defensive patterns

Strategy: validation

Validate before calling

var so = StoreObjectIdentifier.Table("Orders", "dbo");
if (property.GetColumnName(so) is not null)
{
    var root = property.FindSharedStoreObjectRootProperty(so);
}

Type guard

static bool IsPropertyMappedTo(IReadOnlyProperty p, StoreObjectIdentifier so)
    => p.GetColumnName(so) is not null;

Prevention

When it happens

Trigger: Calling FindSharedStoreObjectRootProperty / FindColumnMappings with a StoreObjectIdentifier for a table the property isn't mapped to; iterating all store objects in the model and looking up each property against each.

Common situations: Table-splitting (multiple entities sharing a table) where some properties live on one entity's columns only; TPT hierarchies querying a base-type property against a derived table; views vs. tables mismatch.

Related errors


AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06). Data as JSON: /api/errors/70d94d73e12c689a. Report an issue: GitHub.