Repository navigation
feat: Npgsql 11's native temporal keys accept every range and multirange column - #335
Merged
Merged
Conversation
…nge column Npgsql 11 validates WITHOUT OVERLAPS keys and PERIOD foreign keys by the type mapping, not the store type name: from rc.2 on it accepts any mapping that implements INpgsqlRangeTypeMapping. The range, multirange and YearMonth mappings now implement it, returning no comparer because every range type and RangeSet is already IComparable in PostgreSQL's order. Npgsql EF moves to 11.0.0-rc.2 (the interface does not exist on rc.1.1), EF Core Design to rc.2 in the test projects. NativeTemporalKeyTests holds it on PostgreSQL 18, docs/efcore.md documents it, claims E64-E69. Closes #150 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ep claims sorted Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes CaffeinatedCoder/EFCore.ComplexIndexes#150
Problem
On EF Core 11, Npgsql declares temporal keys itself:
HasKey(…).WithoutOverlaps()andWithPeriod()foreign keys. The issue assumed Npgsql checks the period column's store type. It checks the type mapping, so every column this package maps failed model validation:Measured on PostgreSQL 18 (full table in the issue comment): the refusal holds on rc.1.1 and on rc.2 alike, for
DateRange,TimeRange(customtimerange),RangeSet(datemultirange) and thePERIODforeign key. PostgreSQL 18 itself accepts all of them.The validator's check is
typeMapping is not NpgsqlRangeTypeMappingon rc.1.1. On rc.2 it istypeMapping is not INpgsqlRangeTypeMapping(npgsql/efcore.pg#3975, added for NodaTime's ranges).Change
Npgsql.EntityFrameworkCore.PostgreSQLand its NodaTime plugin move to11.0.0-rc.2, andMicrosoft.EntityFrameworkCore.Designin the two EF test projects to11.0.0-rc.2.26504.105. The interface doesn't exist on rc.1.1. This takes the floor bullet of Publish 11.0.0-preview.1 on the .NET 11 GA SDK and Npgsql's provider rc.3 #332.ValueRangeTypeMapping,ValueRangeSetTypeMapping,YearMonthRangeTypeMappingandYearMonthRangeSetTypeMappingimplementINpgsqlRangeTypeMappingexplicitly.CreateCurrentValueComparerreturnsnull, because every range type andRangeSetis alreadyIComparable<T>in PostgreSQL's order, so EF's default comparer applies.Storage.Internal.Mappingnamespace, and the comment says so. No EF1001 warning fires.NativeTemporalKeyTests(integration, on a PostgreSQL 18 container of its own):DateRange,RangeSet<DateRange, DateOnly>,TimeRangeandYearMonthRangekey: create script,pg_get_constraintdef,btree_gist, adjacent and other-room rows saved, overlap →DbUpdateException/ 23P01 onPK_SlotsPERIODforeign key: covered across two adjacent principals saved, uncovered → 23503SetPostgresVersion(18, 0), the model throws before any SQLNpgsql:WithoutOverlapsRangeSetresolve to anINpgsqlRangeTypeMappingand pass Npgsql's validation (census-checked, so a new type needs no edit)docs/efcore.mdsection, "Reject overlapping rows with Npgsql's temporal keys (PostgreSQL 18)". The ComplexIndexes section below it now opens by saying it is the 10.x (EF Core 10) route.oracles.json, seedmultirange-mapping-not-an-npgsql-range-mapping.patch, and the twopostgres-surface.jsonwaivers now point to the new section with the real API names.### Addedlines in the root, EF Core and EF Core NodaTime changelogs.Tests
SetPostgresVersiontest, is independent of the change. With only the multirange half stripped, the sweep names all 12RangeSettypes. That revert is the committed seed.dotnet run tools/oracles.cs seeds multirange-mapping:CAUGHT … → NativeTemporalKeyTests: 2 of 8 tests fail, e.g. MultirangeKey_RejectsAnOverlap_AndAcceptsAdjacentAndOtherKeys.Not in this PR
HasTemporalConstraintfor them. Npgsql's ownNpgsqlRange<T>[]multirange is still refused by Npgsql.main.🤖 Generated with Claude Code