{"record":{"id":"e3458af59d9488ac","repo":"dotnet/efcore","slug":"the-json-query-expression-for-structuraltype-h","errorCode":null,"errorMessage":"The JSON query expression for '{structuralType}' has no underlying column.","messagePattern":"The JSON query expression for '(.+?)' has no underlying column\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Query/JsonQueryExpression.cs","lineNumber":310,"sourceCode":"        return Update(jsonColumn, newKeyPropertyMap);\n    }\n\n    /// <summary>\n    ///     Finds the <see cref=\"IRelationalJsonElement\" /> for the given property/navigation/complex property within the\n    ///     JSON column referenced by this expression by matching <see cref=\"JsonColumn\" />'s underlying\n    ///     <see cref=\"ColumnExpression.Column\" /> against <see cref=\"IRelationalJsonElement.ContainingColumn\" />. This\n    ///     disambiguates entity-splitting, TPT and TPC scenarios where the same property has multiple JSON element\n    ///     mappings — one per concrete table.\n    ///     <see cref=\"IRelationalJsonElement.PropertyName\" /> may be <see langword=\"null\" /> for shadow keys that have\n    ///     no JSON representation; callers iterating over <see cref=\"ITypeBase.GetProperties\" /> must handle that case\n    ///     and skip them.\n    /// </summary>\n    /// <param name=\"propertyBase\">The property, navigation or complex property to look up.</param>\n    /// <returns>The JSON element mapping for <paramref name=\"propertyBase\" />.</returns>\n    public virtual IRelationalJsonElement GetJsonElement(IPropertyBase propertyBase)\n    {\n        var column = JsonColumn.Column\n            ?? throw new InvalidOperationException(\n                RelationalStrings.JsonQueryExpressionWithoutUnderlyingColumn(StructuralType.DisplayName()));\n        return FindJsonElement(propertyBase)\n            ?? throw new InvalidOperationException(\n                RelationalStrings.JsonElementMappingNotFound(propertyBase.DeclaringType.DisplayName(), propertyBase.Name, column.Name));\n    }\n\n    /// <summary>\n    ///     Finds the <see cref=\"IRelationalJsonElement\" /> for the given property/navigation/complex property within the\n    ///     JSON column referenced by this expression by matching <see cref=\"JsonColumn\" />'s underlying\n    ///     <see cref=\"ColumnExpression.Column\" /> against <see cref=\"IRelationalJsonElement.ContainingColumn\" />, or returns\n    ///     <see langword=\"null\" /> if no such element exists (including when <see cref=\"JsonColumn\" /> has no underlying\n    ///     <see cref=\"ColumnExpression.Column\" />, e.g. for synthetic JSON expansions over OPENJSON / json_each, or for\n    ///     iterated properties such as shadow keys that have no JSON representation).\n    /// </summary>\n    /// <param name=\"propertyBase\">The property, navigation or complex property to look up.</param>\n    /// <returns>The JSON element mapping for <paramref name=\"propertyBase\" />, or <see langword=\"null\" /> if not found.</returns>\n    public virtual IRelationalJsonElement? FindJsonElement(IPropertyBase propertyBase)\n    {","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Query/JsonQueryExpression.cs#L292-L328","documentation":"Thrown by JsonQueryExpression.GetJsonElement when the expression's JsonColumn has no underlying ColumnExpression (Column is null). This means the JSON query expression was constructed for a synthetic or computed JSON source (e.g., OPENJSON/json_each expansion) rather than a real table column, and a concrete column-backed JSON element was expected.","triggerScenarios":"Internal query pipeline calls GetJsonElement on a JsonQueryExpression whose JsonColumn.Column is null. This occurs with provider-specific synthetic JSON expansions (SQL Server OPENJSON, SQLite json_each) or when the JSON column expression is a computed/projection column rather than a base table column.","commonSituations":"Using JSON queries against views or derived tables where the JSON column is computed rather than a physical column. Provider-specific JSON expansion paths (OPENJSON) that create synthetic JSON columns. An EF Core internal bug where a JsonQueryExpression is used before its column binding is established.","solutions":["Ensure JSON-mapped entities are queried directly from their table (not from a view, CTE, or subquery that obscures the column).","If using raw SQL with JSON, ensure the JSON column is selected from the actual table.","Check that your provider version supports the JSON query pattern you're using.","File an issue at https://github.com/dotnet/efcore if this occurs with a standard table-mapped JSON entity."],"exampleFix":"// before — querying JSON entity through a view or subquery that loses the column binding\nvar query = context.CustomerViews // a view, not the base table\n    .Select(c => c.Addresses);\n\n// after — query from the base table directly\nvar query = context.Customers\n    .Select(c => c.Addresses);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var result = await context.Customers.Select(c => c.Addresses).ToListAsync();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"no underlying column\"))\n{\n    logger.LogError(ex, \"JSON query expression has no column backing — query from base table, not view/subquery\");\n    throw;\n}","preventionTips":["Query JSON-mapped entities directly from their base table, not from views or CTEs.","Ensure JSON columns are physical table columns, not computed or derived.","Test JSON queries in integration tests against the real schema.","Report synthetic-column issues to the EF Core team with the provider and query details."],"tags":["json-mapping","query-expression","column-binding","internal-error"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}