Skip to content

Fix nullable value comparer type arguments in compiled models - #39292

Merged
AndriySvyryd merged 2 commits into
mainfrom
copilot/fix-nullablevaluecomparer-issue
Nov 4, 2026
Merged

AndriySvyryd merged 2 commits into
mainfrom
copilot/fix-nullablevaluecomparer-issue

Conversation

Copilot AI commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

A struct’s ValueComparer<T> works with nullable properties at runtime, but compiled models use the comparer class as NullableValueComparer<>’s type argument, causing CS0453.

  • Generation: Use the comparer’s value type, matching runtime wrapping behavior:
    - new NullableValueComparer<QtyComparer>(new QtyComparer())
    + new NullableValueComparer<Qty>(new QtyComparer())
  • Regression coverage: Extend the existing compiled-model comparer test and baseline to cover nullable wrapping, non-nullable properties, explicitly nullable comparers, and equality/snapshot null handling.

Copilot AI changed the title [WIP] Fix error CS0453 in nullable property ValueComparer Fix nullable value comparer type arguments in compiled models Oct 16, 2026
Copilot AI requested a review from AndriySvyryd October 16, 2026 21:55
@AndriySvyryd
AndriySvyryd requested a lite review from Copilot October 17, 2026 04:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved blocking issues were identified.

No open issues 🎉

What changed in this PR

Fixes compiled-model generation for nullable properties using non-nullable struct value comparers.

Changes:

  • Generates NullableValueComparer<T> with the comparer’s value type.
  • Adds regression coverage for nullable and non-nullable comparer scenarios.
  • Updates the compiled-model baseline.
File Description
test/​EFCore.InMemory.FunctionalTests/​Scaffolding/​CompiledModelInMemoryTest.cs Adds comparer behavior regression tests.
test/​EFCore.InMemory.FunctionalTests/​Scaffolding/​Baselines/​Custom_value_comparer/​MyEntityEntityType.cs Updates generated-model baseline expectations.
src/​EFCore.Design/​Scaffolding/​Internal/​CSharpRuntimeModelCodeGenerator.cs Corrects generated comparer generic type arguments.

Review effort: Lite

@AndriySvyryd
AndriySvyryd marked this pull request as ready for review October 17, 2026 04:30
@AndriySvyryd
AndriySvyryd requested a review from a team as a code owner October 17, 2026 04:30
@github-code-quality

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / code-coverage

main 2e88827 copilot/fix-nullable... eca598b +/-
76% 76% 0%
View coverage of the 10 most impacted files.
File main 2e88827 copilot/fix-nullable... eca598b +/-
src/EFCore.Rela...CommandCache.cs 100% 98% -2%
src/EFCore.Rela...alConnection.cs 93% 93% 0%
src/EFCore.Rela...erExtensions.cs 96% 96% 0%
src/EFCore.Anal...icSuppressor.cs 96% 96% 0%
src/EFCore.Cosm...erExtensions.cs 100% 100% 0%
src/EFCore.Cosm...nsExtensions.cs 82% 82% 0%
src/EFCore.Cosm...erExtensions.cs 46% 46% 0%
src/EFCore.Cosm...peExtensions.cs 73% 73% 0%
src/EFCore.Desi...odeGenerator.cs 91% 92% +1%
src/Shared/NonC...yInitializer.cs 11% 12% +1%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.

@AndriySvyryd
AndriySvyryd enabled auto-merge (squash) October 31, 2026 00:27
@AndriySvyryd
AndriySvyryd merged commit b5effd5 into main Nov 4, 2026
29 checks passed
@AndriySvyryd
AndriySvyryd deleted the copilot/fix-nullablevaluecomparer-issue branch November 4, 2026 12:38
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiled model writes NullableValueComparer<TComparer> (CS0453) for a struct's ValueComparer applied to a nullable property

4 participants