Skip to content

Commit 1d313b3

Browse files
authored
Replace our nullability decoding with the new BCL API (#2156)
Closes #2155
1 parent cf4f23e commit 1d313b3

File tree

3 files changed

+17
-145
lines changed

3 files changed

+17
-145
lines changed

src/EFCore.PG/EFCore.PG.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
</ItemGroup>
4747

4848
<ItemGroup>
49-
<None Include="README.md" Pack="true" PackagePath="\"/>
49+
<None Include="README.md" Pack="true" PackagePath="\" />
5050
</ItemGroup>
5151

5252
</Project>

src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Numerics;
88
using System.Text;
99
using System.Text.Json;
10+
using Microsoft.EntityFrameworkCore.Metadata.Internal;
1011
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal;
1112
using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping;
1213
using 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
}

src/EFCore.PG/Utilities/ReferenceNullabilityDecoder.cs

Lines changed: 0 additions & 139 deletions
This file was deleted.

0 commit comments

Comments
 (0)