Skip to content

Translate the calendar factories when they read a column #191

Open

Description

@CaffeinatedCoder

#48 (PR #190) adds DateRange.Month, Quarter, Year and IsoWeek, and the same on LocalDateRange (Quarter and Year on YearMonthRange). Called with values the query does not read, EF evaluates them in memory and inlines one daterange constant, so b.Period.Overlaps(DateRange.Month(2026, 10)) runs as SQL. Called with a column, such as DateRange.Month(b.Day), they fail translation in a Where and run in memory in a Select. docs/efcore.md#what-runs-where lists them as "not translated yet".

Proposed translation (each a [) constructor, so no canonicalization is needed):

  • Month(date) → daterange(date_trunc('month', d)::date, (date_trunc('month', d) + interval '1 month')::date, '[)')
  • Quarter(date), Year(date) → the same with 'quarter' and 'year'
  • IsoWeek(date) → date_trunc('week', d), which is ISO (Monday) in PostgreSQL, plus 7 days
  • Month(y, m), Quarter(y, q), Year(y) → make_date(y, m, 1) and interval arithmetic
  • IsoWeek(weekYear, week) → to_date(weekYear || '-' || week, 'IYYY-IW'), which needs checking against ISOWeek for week 53 of a 52-week year, since the in-memory factory throws there

What to measure first: argument validation. In memory, month 13 or week 53 of a 52-week year throws ArgumentOutOfRangeException. make_date(2026, 13, 1) raises in PostgreSQL, but to_date may roll over, which would be a silent difference. The infinity date extremes (date_trunc('month', 'infinity')) also need checking.

Done when: the column forms run as SQL, a live test compares them with the in-memory answer for every factory over a span of dates, and the row leaves "runs in memory only".

Found while implementing #48, 2026-10-18.

Activity

  1. added
    enhancementNew feature or request
    area/rangesRange unions, variants and the shape engines
    package/efcoreAffects CodoMetis.ValueRanges.EFCore.PostgreSQL
    package/efcore-nodatimeAffects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime
    on Oct 18, 2026
  2. CaffeinatedCoder commented on Oct 18, 2026

    @CaffeinatedCoder
    OwnerAuthor

    Plan (2026-10-18): not part of the 10.0.0 epic (#58). The column forms are additive (a translation failure becomes a working query), so this ships as a 10.x minor, 10.1.0 at the earliest, after the measurements the issue names (to_date rollover on week 53, date_trunc on the date extremes). 10.0.0 tags with the "runs in memory only" row in docs/efcore.md#what-runs-where.

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 enginesenhancementNew feature or requestpackage/efcoreAffects CodoMetis.ValueRanges.EFCore.PostgreSQLpackage/efcore-nodatimeAffects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions