Open dimkr opened 6 months ago
Confirmed, see minimal repro below.
@maumar does this look familiar? I haven't seen an issue already tracking this (putting on your list for now - but not necessarily for fixing right away).
Workaround: query for both sources to union separately and union them on the client.
Problem is SelectExpression.ApplyUnion. When we get there, we have 2 queries as input, whose projection mapping is EmptyProjectionMember to ClassA, which inside stores owned navigation map entry to ClassB (via Test navigation). However in HandleStructuralTypeProjection, where we are supposed to generate the result StructuralTypeProjectionExpression for union, we "lose" the owned navigation map contents. Later, when trying to process Include from ClassA to ClassB via Test, we peek into that owned navigation map and found nothing.
note that this is probably broken for other scenarios as well, basically anything with pushdown (?) - see https://github.com/dotnet/efcore/issues/32911 for potential scenarios to test when fixing this
Workaround: query for both sources to union separately and union them on the client.
In my case, I can't do this because I have many duplicates, I have several performance-critical areas that use set operations and it's UNION
(and not a UNION ALL
) for good reasons. Currently, my workaround is to do the UNION
but .Select(x => x.Id)
at the end, then pass a huge array of IDs to other queries that reference the matching rows: the client never receives the JSON columns, it's a single query and the result is small.
@maumar not a regression, right?
not a regression, exactly same error happens on 7
(Moved from https://github.com/npgsql/efcore.pg/issues/3042)
I'm using Npgsql.EntityFrameworkCore.PostgreSQL 8.0.0 and one table has a JSON column.
Queries on this table fail if they return entities and use .Union():
Minimal repro against sqlite by @WhatzGames: