Skip to content

A projected raw CompareTo against a null range throws; memory answers 1 #253

Closed

Description

@CaffeinatedCoder

Problem

Select(r => r.Seats.CompareTo(none)) with none == null translates to CASE WHEN r."Seats" > NULL THEN 1 WHEN r."Seats" < NULL THEN -1 END. That yields SQL NULL, and materializing it throws "Nullable object must have a value". In memory the call answers 1 (null sorts first). #227's rewriter covers only comparisons with 0. A non-null operand gives the right values. Confirmed live on PostgreSQL 17 by the final pre-release analysis on add665c. It fails loudly.

Change

Apply the same null test the #227 rewriter uses to a raw CompareTo in a projection (CASE WHEN @p IS NULL THEN 1 ELSE … END), or document that a null operand in a projected raw CompareTo throws.

Done when

The projection returns memory's answers for a null and a non-null operand (live test), or the docs and a claim state the exception.

Activity

  1. added this to the 10.0.0 milestone on Oct 19, 2026
  2. added
    bug
    area/ranges
    package/efcore
    severity/low
    on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/rangesbugpackage/efcoreseverity/low

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions