-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong Query Generation for Skip() and Take #31
Comments
From @SimonTouchtech on November 20, 2015 16:6 Seems to be the same as dotnet/efcore#3732? |
@chbach, as @SimonTouchtech suggests this seems to be the same as dotnet/efcore#3732, which is a core EF7 and not an Npgsql problem. Can you please confirm and close this issue if so? |
From @chbach on December 6, 2015 19:26 In fact, I didn't observe this behaviour with SQLite, it only appeared after I switched from SQLite to PostgreSQL. Apart from the wrong query generation, there are still relations missing in the final collection, so something with Include() in combination with Skip() and Take() and the population of relations must be wrong. |
Hi, i have this error in 1.0.1. If i have select before order - it working
and not working (ordering by Include(x => x.User))
and not working to
|
Hi, this code :
seems to produced :
Now with a rapid analyze of this sql code, I understand why it doesn't work... So, I'm not a expert on SQL performance, but a query like this do the job :
Is this problem is related to EF core or to the PGSQL provider ? |
I don't have time to dive into this right now, but there's little chance this is an Npgsql provider issue - it's most likely an EFCore issue. One easy way to help out would be to simply test this on SqlClient with LocalDB - it's really trivial to get a small model together and run this query (see the EFCore getting started). This will at least tell us exactly where the problem is. |
Closing for each, likely to have been fixed in EF Core a long time ago. |
From @chbach on November 18, 2015 20:36
Hi, I recently switched from SQLite to Postgres on EF7 and noticed the following bug. When using
Skip()
andTake()
(LIMIT
andOFFSET
), some relational data would be missing in the resulting collection of objects.I have two models,
NewsEntry
andTag
that are related in a many-to-many relation via the tableTagging
. When I query all NewsEntries withDb.NewsEntries.Include(e => e.Taggings)
, everything works fine and the Tagging-relation is present and I can iterate over them. However, as soon as I start doing something likeDb.NewsEntries.Include(e => e.Taggings).OrderByDescending(e => e.Date).Take(12)
some of the Tagging-relations are missing.I analyzed the generated queries and noticed the following thing. This is the generated query for the relation:
What seems odd to me is that the
ORDER BY
statement is at the very end and sorts the overall result, but should rather sort the NewsEntries, since we want to get the first 12 elements after sorting:You can compare the query with the query the SQLite adapter produces here: dotnet/efcore#3758
Can you please have a look into that?
Christoph
EDIT:
Moving the sorting to the front like
Db.NewsEntries.OrderByDescending(e => e.Date).Include(e => e.Taggings)
actually generates the right query. However there are still Taggings missing! I have no idea how that happens.Copied from original issue: npgsql/npgsql#872
The text was updated successfully, but these errors were encountered: