You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A range set column projected as IReadOnlyList<TRange> or IEnumerable<TRange> fails on the server with 42846 #585
Found by a pre-release sweep of main @ 577b85e (lens: framework-heuristics, from a lead); run against PostgreSQL 16. Probably not new in 11.0.0: the 10.x RangeSet<TRange, T> is an IReadOnlyList<TRange> too (not run there).
Problem
A final Select that hands a range set column to something typed as a collection of its ranges fails on the server:
db.Reservations.Select(r =>new{Blocked=(IReadOnlyList<DateRange>)r.BlockedDays})// the same for a DTO member declared IReadOnlyList<DateRange> or IEnumerable<DateRange>,// where the compiler writes the conversion
SELECT r."BlockedDays"::daterange[] AS"L"FROM"Reservations"AS r
PostgresException: 42846: cannot cast type datemultirange to daterange[]
EF Core translates the conversion to the interface as a cast to the array mapping Npgsql has for a list of ranges. PostgreSQL has no such cast.
It fails loudly, with a server error that does not say what to write instead. ToList() is the way round it.
Change
Keep the conversion out of the SQL: the column is read as the set, and the conversion to an interface the set implements runs in memory, as ToList() does. Where that happens (the interceptor before translation, or the type mapping source declining the array mapping for a set-typed operand) is to be decided against EF Core 11's own handling of a converted column in a projection. Related: #94 (enumeration of a multirange column) and #407.
Test
An integration test over every discovered range set type that projects the column as each BCL collection interface it implements, into an anonymous type and a DTO member, and compares with the loaded set. It fails with 42846 without the change.
Activity
fix: load a range set column projected as a collection interface (#585)
Merge pull request #593 from CaffeinatedCoder/fix/585-range-set-as-in…
Merge pull request #610 from CaffeinatedCoder/fix/608-range-set-as-in…