Skip to content

Translate Values() and Values(step) on the discrete ranges #651

Backlog

Description

@CaffeinatedCoder

Split from #407 (the enumeration family).

Problem

Values() and Values(step) on the discrete ranges (Int32Range, Int64Range, DateRange, LocalDateRange, YearMonthRange) run in memory only.

Change

ARRAY(SELECT generate_series(lower(r), upper(r) - 1, step)), with:

  • the result an IEnumerable<T> EF Core can read as an array of the element (to be measured: whether Npgsql materializes IEnumerable<T> from a T[] mapping, or whether this needs the element's array mapping of our own);
  • the empty range as {}, NULL as NULL, unbounded raising as memory throws;
  • the date extremes and the infinity conversions as in the bridge issue split from Translate enumeration and the bridge conversions — a batch after 10.3.0 #407;
  • step ≤ 0 raising as memory throws.

Done when

SQL asserted without a database, a live parity test on 16 and 18 per type (empty, NULL, one value, steps that do and do not divide the length, extremes, unbounded), translation-support.json and docs/efcore.md#what-runs-where updated, claim + seed.

Activity

  1. added this to the 11.0.0 milestone on Nov 30, 2026
  2. added
    enhancement
    area/ranges
    package/efcore
    package/efcore-nodatime
    on Nov 30, 2026
  3. CaffeinatedCoder commented on Nov 30, 2026

    @CaffeinatedCoder
    OwnerAuthor

    Measured (2026-11-30, main @ fc87c98, no database: IRelationalTypeMappingSource.FindMapping on a context with UseValueRangesNodaTime()): Npgsql already maps IEnumerable<T> for four of the five elements. It returns its own NpgsqlArrayTypeMapping with an NpgsqlArrayConverter (reads T[], hands back the interface):

    CLR type store type
    IEnumerable<int> integer[]
    IEnumerable<long> bigint[]
    IEnumerable<DateOnly> date[]
    IEnumerable<LocalDate> date[]
    IEnumerable<YearMonth> none: the element is this library's (a month-aligned date), so its array mapping is ours to add, as YearMonthSet does

    So the translator can take FindMapping(typeof(IEnumerable<T>)) for the BCL and LocalDate elements. A live read is still owed: the converter is only exercised when a row is materialized. #650's ValueSetSqlGuard.Values (unnest + generate_series, the date extremes, the unbounded raise) is the builder to extend. A single range can go in as multirange(r), and step adds a third generate_series argument (step * INTERVAL '1 day' for dates, months for YearMonth), with a raise for step <= 0.

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/rangesenhancementpackage/efcorepackage/efcore-nodatime

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions