@@ -199,14 +199,14 @@ protected override ShapedQueryExpression TransformJsonQueryToTable(JsonQueryExpr
199199 } ;
200200
201201 var jsonTypeMapping = jsonQueryExpression . JsonColumn . TypeMapping ! ;
202- Check . DebugAssert ( jsonTypeMapping is NpgsqlOwnedJsonTypeMapping , "JSON column has a non-JSON mapping" ) ;
202+ Check . DebugAssert ( jsonTypeMapping is NpgsqlStructuralJsonTypeMapping , "JSON column has a non-JSON mapping" ) ;
203203
204204 // We now add all of projected entity's the properties and navigations into the jsonb_to_recordset's AS clause, which defines the
205205 // names and types of columns to come out of the JSON fragments.
206206 var columnInfos = new List < PgTableValuedFunctionExpression . ColumnInfo > ( ) ;
207207
208208 // We're only interested in properties which actually exist in the JSON, filter out uninteresting shadow keys
209- foreach ( var property in GetAllPropertiesInHierarchy ( jsonQueryExpression . EntityType ) )
209+ foreach ( var property in jsonQueryExpression . StructuralType . GetPropertiesInHierarchy ( ) )
210210 {
211211 if ( property . GetJsonPropertyName ( ) is string jsonPropertyName )
212212 {
@@ -218,18 +218,37 @@ protected override ShapedQueryExpression TransformJsonQueryToTable(JsonQueryExpr
218218 }
219219 }
220220
221- // Navigations represent nested JSON owned entities, which we also add to the AS clause, but with the JSON type.
222- foreach ( var navigation in GetAllNavigationsInHierarchy ( jsonQueryExpression . EntityType )
223- . Where (
224- n => n . ForeignKey . IsOwnership
225- && n . TargetEntityType . IsMappedToJson ( )
226- && n . ForeignKey . PrincipalToDependent == n ) )
221+ switch ( jsonQueryExpression . StructuralType )
227222 {
228- var jsonNavigationName = navigation . TargetEntityType . GetJsonPropertyName ( ) ;
229- Check . DebugAssert ( jsonNavigationName is not null , $ "No JSON property name for navigation { navigation . Name } ") ;
223+ case IEntityType entityType :
224+ foreach ( var navigation in entityType . GetNavigationsInHierarchy ( )
225+ . Where ( n => n . ForeignKey . IsOwnership
226+ && n . TargetEntityType . IsMappedToJson ( )
227+ && n . ForeignKey . PrincipalToDependent == n ) )
228+ {
229+ var jsonNavigationName = navigation . TargetEntityType . GetJsonPropertyName ( ) ;
230+ Check . DebugAssert ( jsonNavigationName is not null , $ "No JSON property name for navigation { navigation . Name } ") ;
231+
232+ columnInfos . Add (
233+ new PgTableValuedFunctionExpression . ColumnInfo { Name = jsonNavigationName , TypeMapping = jsonTypeMapping } ) ;
234+ }
235+
236+ break ;
237+
238+ case IComplexType complexType :
239+ foreach ( var complexProperty in complexType . GetComplexProperties ( ) )
240+ {
241+ var jsonPropertyName = complexProperty . ComplexType . GetJsonPropertyName ( ) ;
242+ Check . DebugAssert ( jsonPropertyName is not null , $ "No JSON property name for complex property { complexProperty . Name } ") ;
230243
231- columnInfos . Add (
232- new PgTableValuedFunctionExpression . ColumnInfo { Name = jsonNavigationName , TypeMapping = jsonTypeMapping } ) ;
244+ columnInfos . Add (
245+ new PgTableValuedFunctionExpression . ColumnInfo { Name = jsonPropertyName , TypeMapping = jsonTypeMapping } ) ;
246+ }
247+
248+ break ;
249+
250+ default :
251+ throw new UnreachableException ( ) ;
233252 }
234253
235254 // json_to_recordset requires the nested JSON document - it does not accept a path within a containing JSON document (like SQL
@@ -254,21 +273,12 @@ protected override ShapedQueryExpression TransformJsonQueryToTable(JsonQueryExpr
254273 return new ShapedQueryExpression (
255274 selectExpression ,
256275 new RelationalStructuralTypeShaperExpression (
257- jsonQueryExpression . EntityType ,
276+ jsonQueryExpression . StructuralType ,
258277 new ProjectionBindingExpression (
259278 selectExpression ,
260279 new ProjectionMember ( ) ,
261280 typeof ( ValueBuffer ) ) ,
262281 false ) ) ;
263-
264- // TODO: Move these to IEntityType?
265- static IEnumerable < IProperty > GetAllPropertiesInHierarchy ( IEntityType entityType )
266- => entityType . GetAllBaseTypes ( ) . Concat ( entityType . GetDerivedTypesInclusive ( ) )
267- . SelectMany ( t => t . GetDeclaredProperties ( ) ) ;
268-
269- static IEnumerable < INavigation > GetAllNavigationsInHierarchy ( IEntityType entityType )
270- => entityType . GetAllBaseTypes ( ) . Concat ( entityType . GetDerivedTypesInclusive ( ) )
271- . SelectMany ( t => t . GetDeclaredNavigations ( ) ) ;
272282 }
273283
274284 /// <summary>
0 commit comments