Skip to content

A widening the translator leaves out is a cast in EF Core's query: x.Int == 5L is stored as {Int} = 5, and the index does not serve "Int"::bigint = 5 #125

Open

Description

@CaffeinatedCoder

Found while fixing #103, by crossing the parity sweep with the new table of conversions the translator leaves out (LambdaTranslator.SilentConversions). Until then the sweep compared a column only with a value of its own type.

What happens

For a comparison of two integer types the C# compiler widens the narrower side: x.Int == 5L arrives as Convert(x.Int, Int64) == 5. The translator leaves the conversion out, which keeps the answer: {Int} = 5. EF Core's query for the same lambda writes it:

-- the declaration                 -- EF Core's query
"Int" = 5                          p."Int"::bigint = 5
"Short" < "Long"                   p."Short"::bigint < p."Long"
"Byte" = 5   -- (ushort)x.Byte     p."Byte"::int = 5
"Byte" = 5   -- x.Byte == 5ul      p."Byte"::numeric(20,0) = 5.0

Both select the same rows (the live sweep runs every such row on PostgreSQL 18). But PostgreSQL uses a partial index only for a query whose predicate it can prove from the index's, and it does not look through the cast:

create index ix on t("Id") where "Int" = 5;
explain select "Id" from t where "Int" = 5;          -- Index Only Scan using ix
explain select "Id" from t where "Int"::bigint = 5;  -- Seq Scan, Filter: (("Int")::bigint = 5)

So a filter declared with such a comparison is right about its rows and does not serve the query written with the same lambda, which is the reason the translator spells things as the provider's queries do. Nothing is cast where both types have one store type (byte and short are both smallint on PostgreSQL), so which widenings are affected is the provider's type mapping, not C#'s.

Change

When casts are rendered with the provider's spelling (#112, #114), a widening whose two types have different store types is written as the provider's query writes it. Until then the 432 rows are waived in waivers.txt under "A widening EF Core writes as a cast", and the block shrinks to nothing with the fix.

Test

The waiver block goes; the rows agree.

Activity

  1. added this to the 11.0.0 milestone on Nov 14, 2026
  2. added
    bug
    package/core
    severity/low
    area/expression-indexes
    on Nov 14, 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/expression-indexesbugpackage/coreseverity/low

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions