Skip to content

CompareTo(null) compared with ±1 in a query still returns no rows #256

Closed

Description

@CaffeinatedCoder

Problem

#227 (fixing #220) rewrote CompareTo(null) compared with 0, but EF Core's optimizer turns more forms into comparison operators: CompareTo(x) == 1, >= 1, > -1, != -1 and 1 == CompareTo(x). With a null operand they returned 0 of 7 rows on the server against 7 of 7 in memory, where CompareTo(null) is exactly 1. ExecuteUpdate with CompareTo(none) == 1 updated 0 of 7 rows. Non-null operands agree. Found live by the final pre-release analysis on add665c (pass A), at ValueRangesQueryExpressionInterceptor.cs:249: IsZero matches only 0.

It is outside the documented "against 0" sentence, but it translates silently instead of refusing.

Change

Make the rewrite accept -1, 0 and 1, and give the null-operand answer for each operator and constant (CompareTo(null) is 1: == 1, >= 1, > -1, > 0, >= 0, != -1, != 0 are true; == 0, == -1, < 0, <= 0, < 1, <= -1 are false). Or refuse the forms it can't rewrite. The answer must never be silently different.

Done when

RangeOrderParityTests.CompareToInAQuery_ReturnsTheRowsMemoryReturns has the five predicates above, and the 0-forms, with a null operand, and fails with the extension reverted.

Activity

  1. added this to the 10.0.0 milestone on Oct 19, 2026
  2. added
    bugSomething isn't working
    silentAnswers wrongly without throwing — fixes go in the next major, never deferred
    area/rangesRange unions, variants and the shape engines
    package/efcoreAffects CodoMetis.ValueRanges.EFCore.PostgreSQL
    severity/lowCosmetic, message or documentation-level difference
    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/rangesRange unions, variants and the shape enginesbugSomething isn't workingpackage/efcoreAffects CodoMetis.ValueRanges.EFCore.PostgreSQLseverity/lowCosmetic, message or documentation-level differencesilentAnswers wrongly without throwing — fixes go in the next major, never deferred

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions