@@ -43,29 +43,25 @@ public override object ToObject()
4343 var structuralObject = StructuralType . GetOrCreateMaterializer ( MaterializerSource ) (
4444 new MaterializationContext ( new ValueBuffer ( _values ) , InternalEntry . Context ) ) ;
4545
46- if ( _nullComplexPropertyFlags != null && NullableComplexProperties != null )
46+ if ( _nullComplexPropertyFlags != null && NullableComplexProperties != null && StructuralType is not IComplexType )
4747 {
48+ // Only handle nullable complex properties for entities, not for complex collection items
49+ // Complex collection items' nested nulls are handled recursively
4850 var isValueType = StructuralType . ClrType . IsValueType ;
49- var isComplexType = StructuralType is IComplexType ;
5051
5152 for ( var i = 0 ; i < _nullComplexPropertyFlags . Length ; i ++ )
5253 {
5354 if ( _nullComplexPropertyFlags [ i ] )
5455 {
5556 var complexProperty = NullableComplexProperties [ i ] ;
5657
57- // Only set if the complex property is declared directly on the current structural type
58- // Nested properties will be set when ToObject() is called recursively on them
59- if ( complexProperty . DeclaringType == StructuralType )
58+ if ( isValueType )
6059 {
61- if ( isValueType || isComplexType )
62- {
63- structuralObject = ( ( IRuntimeComplexProperty ) complexProperty ) . GetSetter ( ) . SetClrValue ( structuralObject , null ) ;
64- }
65- else
66- {
67- ( ( IRuntimeComplexProperty ) complexProperty ) . GetSetter ( ) . SetClrValueUsingContainingEntity ( structuralObject , null ) ;
68- }
60+ structuralObject = ( ( IRuntimeComplexProperty ) complexProperty ) . GetSetter ( ) . SetClrValue ( structuralObject , null ) ;
61+ }
62+ else
63+ {
64+ ( ( IRuntimeComplexProperty ) complexProperty ) . GetSetter ( ) . SetClrValueUsingContainingEntity ( structuralObject , null ) ;
6965 }
7066 }
7167 }
0 commit comments