You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix parameter collections of nullable structs #3408
See PrimitiveCollectionsQueryNpgsqlTest.{Parameter_collection_of_nullable_structs_Contains_nullable_struct_with_nullable_comparer,Parameter_collection_of_structs_Contains_nullable_struct_with_nullable_comparer}.
The below is an AI-generated analysis and may contain inaccuracies.
Confirmed bug, already fixed on current main. The two tests mentioned in this issue cover distinct failures, both of which can be reproduced during query compilation with ToQueryString(); no database or seed data is needed.
Results
These are standalone console-program results. "Pass" means SQL generation completed, not that a database query was executed.
Provider / version
List<WrappedId?> containing null
List<WrappedId> against nullable property .Value
Npgsql 7.0.18
Pass
InvalidCastException: Object must implement IConvertible
Released-package comparisons used .NET 10.0.8; current Npgsql source used the repository's .NET 11 RC2 SDK and EF Core 11.0.0-rc.2.26504.105.
Regression assessment: The nullable-list case works in Npgsql 7.0.18 but fails in 8.0.11, so this predates EF/Npgsql 9; the exact first failing 8.x release was not bisected. The non-nullable-list case already fails on Npgsql 7.0.18, so it is not a newly introduced 9.0 regression either. SQL Server has a separate confirmed 8-to-9 regression in the second case.
Fixes and related issues
The nullable-list failure is the missing-constructor/JSON element reader-writer mismatch fixed by #3843, which also enabled Parameter_collection_of_nullable_structs_Contains_nullable_struct_with_nullable_comparer. It was backported to 10.0.3, matching the result above. Related duplicate reports: #3842 and #3716.
The non-nullable-list failure is in NpgsqlArrayConverter: the collection supplies WrappedId, but the element conversion expression accepts WrappedId?. The inner exception is ArgumentException: Expression of type 'WrappedId' cannot be used for parameter of type 'System.Nullable<WrappedId>'. This is #3919, fixed by #3965, which also enabled Parameter_collection_of_structs_Contains_nullable_struct_with_nullable_comparer. Backports are already merged for 10.0 (#3967), 9.0 (#3968), and 8.0 (#3969). The tested 10.0.3 release still fails this case.
Upstream, dotnet/efcore#35117 is an exact match for the SQL Server 9 non-nullable-list/value-comparer failure. It was fixed for EF 10 by dotnet/efcore#35235; the upstream discussion explicitly declined a 9.0 backport in favor of using a non-nullable value converter. dotnet/efcore#36873 is a related comparer-type mismatch report, but uses enum/int types rather than nullable struct converters and was closed without a reproducer.
The SQL Server 9 overlap does not explain away the Npgsql bugs: Npgsql still fails with EF 10, where SQL Server passes. This issue belongs in the provider repository rather than needing to be reopened upstream.
Recommendation: Close this issue as resolved on main by #3843 and #3965. The requested non-nullable conversion backports have already been merged; that does not establish that the nullable-list scenario is fixed on the 8.0/9.0 branches.
A workaround on affected releases is to define the converter over WrappedId and int, rather than WrappedId? and int?; EF handles nulls around ordinary converters.
minimal repro
Create a console project with the following project file and Program.cs. Both failures reproduce with provider 9.0.0. Run dotnet run for the nullable-list case, and dotnet run -- non-nullable for the other case.
usingMicrosoft.EntityFrameworkCore;usingMicrosoft.EntityFrameworkCore.Storage.ValueConversion;usingMicrosoft.Extensions.Logging;awaitusingvarcontext=newTestContext();if(args.Contains("non-nullable")){varvalues=newList<WrappedId>{new(22),new(33)};_=context.Set<PrimitiveCollectionsEntity>().Where(c =>values.Contains(c.NullableWrappedIdWithNullableComparer!.Value)).ToQueryString();}else{varvalues=newList<WrappedId?>{null,new(22)};_=context.Set<PrimitiveCollectionsEntity>().Where(c =>values.Contains(c.NullableWrappedIdWithNullableComparer)).ToQueryString();}publicclassTestContext:DbContext{protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptionsBuilder)=>optionsBuilder.UseNpgsql("Host=localhost;Database=issue3408").LogTo(Console.WriteLine,LogLevel.Information).EnableSensitiveDataLogging();protectedoverridevoidOnModelCreating(ModelBuildermodelBuilder)=>modelBuilder.Entity<PrimitiveCollectionsEntity>().Property(e =>e.NullableWrappedIdWithNullableComparer).HasConversion<NullableWrappedIdConverter>();}publicclassNullableWrappedIdConverter():ValueConverter<WrappedId?,int?>(
id =>id==null?null:id.Value.Value,
value =>value==null?null:newWrappedId(value.Value));publicclassPrimitiveCollectionsEntity{publicintId{get;set;}publicWrappedId?NullableWrappedIdWithNullableComparer{get;set;}}publicreadonlyrecordstructWrappedId(intValue);
To repeat the SQL Server comparison, replace the package with Microsoft.EntityFrameworkCore.SqlServer at the same EF version and replace UseNpgsql(...) with UseSqlServer("Server=localhost;Database=issue3408;Integrated Security=true;TrustServerCertificate=true"). No server is contacted by either variant.
Activity
roji commentedon Oct 17, 2026
AI Triage
The below is an AI-generated analysis and may contain inaccuracies.
Confirmed bug, already fixed on current
main. The two tests mentioned in this issue cover distinct failures, both of which can be reproduced during query compilation withToQueryString(); no database or seed data is needed.Results
These are standalone console-program results. "Pass" means SQL generation completed, not that a database query was executed.
List<WrappedId?>containing nullList<WrappedId>against nullable property.ValueInvalidCastException: Object must implement IConvertiblemainat e420326eReleased-package comparisons used .NET 10.0.8; current Npgsql source used the repository's .NET 11 RC2 SDK and EF Core
11.0.0-rc.2.26504.105.Regression assessment: The nullable-list case works in Npgsql 7.0.18 but fails in 8.0.11, so this predates EF/Npgsql 9; the exact first failing 8.x release was not bisected. The non-nullable-list case already fails on Npgsql 7.0.18, so it is not a newly introduced 9.0 regression either. SQL Server has a separate confirmed 8-to-9 regression in the second case.
Fixes and related issues
Parameter_collection_of_nullable_structs_Contains_nullable_struct_with_nullable_comparer. It was backported to 10.0.3, matching the result above. Related duplicate reports: #3842 and #3716.NpgsqlArrayConverter: the collection suppliesWrappedId, but the element conversion expression acceptsWrappedId?. The inner exception isArgumentException: Expression of type 'WrappedId' cannot be used for parameter of type 'System.Nullable<WrappedId>'. This is #3919, fixed by #3965, which also enabledParameter_collection_of_structs_Contains_nullable_struct_with_nullable_comparer. Backports are already merged for 10.0 (#3967), 9.0 (#3968), and 8.0 (#3969). The tested 10.0.3 release still fails this case.The SQL Server 9 overlap does not explain away the Npgsql bugs: Npgsql still fails with EF 10, where SQL Server passes. This issue belongs in the provider repository rather than needing to be reopened upstream.
Recommendation: Close this issue as resolved on
mainby #3843 and #3965. The requested non-nullable conversion backports have already been merged; that does not establish that the nullable-list scenario is fixed on the 8.0/9.0 branches.A workaround on affected releases is to define the converter over
WrappedIdandint, rather thanWrappedId?andint?; EF handles nulls around ordinary converters.minimal repro
Create a console project with the following project file and
Program.cs. Both failures reproduce with provider 9.0.0. Rundotnet runfor the nullable-list case, anddotnet run -- non-nullablefor the other case.To repeat the SQL Server comparison, replace the package with
Microsoft.EntityFrameworkCore.SqlServerat the same EF version and replaceUseNpgsql(...)withUseSqlServer("Server=localhost;Database=issue3408;Integrated Security=true;TrustServerCertificate=true"). No server is contacted by either variant.roji commentedon Oct 17, 2026
Duplicate of #3843 and #3965