77using System . Numerics ;
88using System . Text ;
99using System . Text . Json ;
10+ using Microsoft . EntityFrameworkCore . Metadata . Internal ;
1011using Npgsql . EntityFrameworkCore . PostgreSQL . Infrastructure . Internal ;
1112using Npgsql . EntityFrameworkCore . PostgreSQL . Storage . Internal . Mapping ;
1213using Npgsql . EntityFrameworkCore . PostgreSQL . Utilities ;
@@ -32,7 +33,7 @@ static NpgsqlTypeMappingSource()
3233 }
3334
3435 private readonly ISqlGenerationHelper _sqlGenerationHelper ;
35- private readonly ReferenceNullabilityDecoder _referenceNullabilityDecoder = new ( ) ;
36+ private readonly NullabilityInfoContext _nullabilityInfoContext = new ( ) ;
3637
3738 protected virtual ConcurrentDictionary < string , RelationalTypeMapping [ ] > StoreTypeMappings { get ; }
3839 protected virtual ConcurrentDictionary < Type , RelationalTypeMapping > ClrTypeMappings { get ; }
@@ -827,11 +828,21 @@ private static bool NameBasesUsesPrecision(ReadOnlySpan<char> span)
827828 // We decode NRT annotations here to return the correct type mapping.
828829 if ( mapping is NpgsqlArrayTypeMapping arrayMapping
829830 && ! arrayMapping . ElementMapping . ClrType . IsValueType
830- && ! property . IsShadowProperty ( )
831- && property . GetMemberInfo ( forMaterialization : false , forSet : false ) is { } memberInfo
832- && memberInfo . GetMemberType ( ) . IsArrayOrGenericList ( ) )
831+ && ! property . IsShadowProperty ( ) )
833832 {
834- if ( _referenceNullabilityDecoder . IsArrayOrListElementNonNullable ( memberInfo ) )
833+ var nullabilityInfo =
834+ property . PropertyInfo is { } propertyInfo
835+ ? _nullabilityInfoContext . Create ( propertyInfo )
836+ : property . FieldInfo is { } fieldInfo
837+ ? _nullabilityInfoContext . Create ( fieldInfo )
838+ : null ;
839+
840+ // We already know from the mapping check above that the member is either an array or a generic list
841+ var elementNullabilityInfo = nullabilityInfo ? . ElementType
842+ ?? ( nullabilityInfo ? . GenericTypeArguments . Length > 0 ? nullabilityInfo . GenericTypeArguments [ 0 ] : null ) ;
843+
844+ if ( elementNullabilityInfo ? . ReadState == NullabilityState . NotNull
845+ && elementNullabilityInfo . WriteState == NullabilityState . NotNull )
835846 {
836847 return arrayMapping . MakeNonNullable ( ) ;
837848 }
0 commit comments