Unable to translate collection subquery in projection
See original GitHub issueI have come across an issue where I’m unable to construct a suitably performant query with a group by clause. I have seen a simliar issue with the same error message. However, all models have a key. I can rewrite the query used to use Contains instead of a join, but the query produced is 100x slower (30 seconds instead of 0.3 seconds) so I’m not sure where to go from here. I have attached a minimal example efcore-sample.zip
The error message is as follows:
Unable to translate collection subquery in projection since the parent query doesn’t project key columns of all of it’s tables which are required to generate results on client side. This can happen when trying to correlate on keyless entity or when using ‘Distinct’ or ‘GroupBy’ operations without projecting all of the key columns.
Unfortunately in this small example I can’t easily generate enough data to show the performance issue in the second query (Manually rewriting the query using IN (Select .....)
as opposed to WHERE EXISTS(....HAVING)
is also orders of magnitude quicker but I was unable to generate a query which used the IN operator) but in the real dataset the “books” table has 7475 rows and the “bookauthors” table has 31557 rows. ThenInclude isn’t used so Authors isn’t actually relevant
Include provider and version information
EF Core version: 5.08 Database provider: Npgsql.EntityFrameworkCore.PostgreSQL Target framework: .NET 5.0 Operating system: Windows 10 IDE: Visual Studio Code 1.58.2
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (5 by maintainers)
@roji - This uses preview6 packages with npgsql provider. Can you try the sample app on latest release?
TODO: add regression test