Skip to content

Support NodaTime ranges in temporal constraints - #3975

Merged
roji merged 3 commits into
mainfrom
roji-nodatime-temporal-keys
Oct 16, 2026
Merged

roji merged 3 commits into
mainfrom
roji-nodatime-temporal-keys

Conversation

@roji

@roji roji commented Oct 16, 2026

Copy link
Copy Markdown
Member

Interval and DateInterval currently fail model validation when used in WITHOUT OVERLAPS keys or PERIOD foreign keys because they lack ordering comparers and their mappings are not recognized as range mappings.

Introduce a shared range-mapping interface so each mapping supplies its current-value comparer. Model validation and both model-finalizing and runtime-model conventions use this interface, keeping NodaTime-specific ordering in the plugin. Unbounded Interval endpoints are supported.

Adds comparer coverage and PostgreSQL integration coverage for primary and alternate keys, temporal foreign keys, and insert/update/delete operations for both NodaTime types.

Fixes #3824

Allow range mappings to supply their current-value comparers for model validation and update ordering. Support Interval and DateInterval temporal keys and foreign keys, including unbounded intervals.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: df0d9290-49c9-4f4b-a74d-cb3824f85429
Copilot AI balanced review requested due to automatic review settings October 16, 2026 10:21
@roji
roji enabled auto-merge (squash) October 16, 2026 10:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Both new NodaTime comparers ignore value converters, causing command sorting failures for converted keys.

2 open findings
What changed in this PR

Enables NodaTime ranges in PostgreSQL temporal constraints, addressing #3824 while keeping NodaTime-specific ordering in the plugin.

Changes:

  • Introduces a shared range-mapping interface for validation and comparer creation.
  • Adds Interval and DateInterval ordering, including unbounded Interval endpoints.
  • Adds comparer tests and temporal-constraint integration coverage.
File Description
test/​EFCore.PG.Tests/​Storage/​NpgsqlNodaTimeTypeMappingTest.cs Tests NodaTime comparer ordering.
test/​EFCore.PG.FunctionalTests/​TemporalConstraintNodaTimeTest.cs Exercises temporal keys, foreign keys, and persistence.
src/​EFCore.PG/​Storage/​Internal/​Mapping/​NpgsqlRangeTypeMapping.cs Implements the shared comparer factory.
src/​EFCore.PG/​Storage/​Internal/​Mapping/​INpgsqlRangeTypeMapping.cs Defines the shared range-mapping contract.
src/​EFCore.PG/​Metadata/​Conventions/​NpgsqlRuntimeModelConvention.cs Uses mapping-provided runtime comparers.
src/​EFCore.PG/​Metadata/​Conventions/​NpgsqlPostgresModelFinalizingConvention.cs Installs mapping-provided comparers during finalization.
src/​EFCore.PG/​Infrastructure/​Internal/​NpgsqlModelValidator.cs Recognizes plugin range mappings.
src/​EFCore.PG.NodaTime/​Storage/​Internal/​IntervalRangeMapping.cs Adds interval ordering with unbounded endpoints.
src/​EFCore.PG.NodaTime/​Storage/​Internal/​DateIntervalRangeMapping.cs Adds date-interval ordering.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@roji
roji disabled auto-merge October 16, 2026 10:29
Only install range-specific current-value comparers for unconverted mappings, preserving EF's existing model/provider ordering for converted keys. Cover int and long keys converted to NodaTime ranges with and without temporal constraints.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: df0d9290-49c9-4f4b-a74d-cb3824f85429
Copilot AI balanced review requested due to automatic review settings October 16, 2026 10:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The converter guards remove required ordering comparers from existing range-valued keys using range-to-range conversions.

1 open finding
2 resolved since last review

🧠 Review effort: Balanced

Preserve range-valued key ordering across same-type and cross-type value conversions, while leaving comparable scalar model values to EF's comparer. Cover model validation and multiple-row saves for both range conversion cases.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: df0d9290-49c9-4f4b-a74d-cb3824f85429
Copilot AI balanced review requested due to automatic review settings October 16, 2026 10:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

Static review identified no blocking issues, and regression coverage addresses temporal operations and converted-key compatibility; tests were not executed.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support NodaTime.Interval when using WithoutOverlaps()

2 participants