{"record":{"id":"ad7bea2799ea7fd8","repo":"dotnet/efcore","slug":"no-json-element-mapping-was-found-for-structural","errorCode":null,"errorMessage":"No JSON element mapping was found for '{structuralType}.{name}' on column '{columnName}'.","messagePattern":"No JSON element mapping was found for '(.+?)\\.(.+?)' on column '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Query/JsonQueryExpression.cs","lineNumber":313,"sourceCode":"    /// <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    {\n        var containingColumn = JsonColumn.Column;\n        if (containingColumn is null)\n        {","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Query/JsonQueryExpression.cs#L295-L331","documentation":"Thrown by JsonQueryExpression.GetJsonElement when FindJsonElement returns null for the given property/navigation/complex property. The JSON column exists, but no IRelationalJsonElement mapping was registered for this specific propertyBase on that column — meaning the model knows the property exists but has no JSON path mapping for it on this particular column.","triggerScenarios":"Internal query pipeline calls GetJsonElement for a property that has no JSON element mapping on the current column. This can happen with entity splitting, TPT, or TPC where the same property maps to different tables but the JSON element mapping exists only for one table's column. Also occurs with shadow keys that have no JSON representation if the caller doesn't skip them.","commonSituations":"Entity splitting or TPT/TPC inheritance where a JSON-mapped owned type spans multiple tables, and the property is accessed through a path bound to the wrong table's column. Shadow properties used as keys in JSON entities without explicit JSON element configuration. Incomplete model configuration where ToJson is applied but not all properties have consistent mappings.","solutions":["Verify the JSON mapping configuration covers all properties being queried — check ToJson() and column mapping consistency.","If using inheritance or entity splitting, ensure JSON element mappings exist for the correct table/column.","For shadow keys, ensure callers skip properties that have no JSON representation (PropertyName may be null).","File an issue at https://github.com/dotnet/efcore with the model configuration if mappings appear correct."],"exampleFix":"// before — incomplete JSON mapping\nmodelBuilder.Entity<Customer>().OwnsMany(c => c.Addresses, a =>\n{\n    a.ToJson(\"addresses\");\n    // some properties lack explicit mapping, TPT splits across tables\n});\n\n// after — ensure all properties have consistent JSON element mappings\nmodelBuilder.Entity<Customer>().OwnsMany(c => c.Addresses, a =>\n{\n    a.ToJson(\"addresses\");\n    a.Property(x => x.City).HasColumnName(\"city\");\n    a.Property(x => x.ZipCode).HasColumnName(\"zip\");\n});","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var result = await context.Customers\n        .Where(c => c.Addresses.Any(a => a.City == \"NYC\"))\n        .ToListAsync();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"No JSON element mapping was found\"))\n{\n    logger.LogError(ex, \"JSON element mapping missing — check ToJson configuration for all properties\");\n    throw;\n}","preventionTips":["Ensure ToJson mapping is applied consistently and all properties have JSON element mappings.","For TPT/TPC + JSON scenarios, verify each table's JSON column has complete element mappings.","Skip shadow key properties when iterating JSON-mapped entity properties (they may have null PropertyName).","Write integration tests that exercise every JSON property in queries."],"tags":["json-mapping","element-mapping","tpt-tpc","internal-error"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}