-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Translate Queryable.Reverse #17388
Comments
Notes from triage: Reverse is only meaningful if we have a stable order to begin with. In that case the implementation here is to reverse that order. Throw for other cases. |
Hi all. I've chosen this issue to start getting familiar with the EF sources. I've drafted the first implementation and found that it is easy to do if For example, should this be a valid query?
|
@Pankraty - Thanks for showing interest in contributing for this issue. As per triage decision above, it is fine to throw exception if there is no ordering coming before Reverse. For InMemory it would just work how it works in linq. So nothing complicated needed there either. The query you posted above is valid query since, there is ordering present before select. Many operators preserves inner ordering, especially when they are not doing any comparison. For implementation, I would recommended adding some tests (which would of course fail) first since there would be different parts of query pipeline which may need to handle this operator. I would happy to guide you if you are unsure what should happen to this operator in any part. |
@smitpatel thanks for offering help! Before you wrote I prepared this implementation (#19185) but tomorow I will try to do as you've suggested. |
Resolves #17388 In order to translate Reverse, we reverse the existing ordering. If there is no existing ordering then we throw translation failure.
Resolves #17388 In order to translate Reverse, we reverse the existing ordering. If there is no existing ordering then we throw translation failure.
IMO, i don't think it's a good idea for to implement the .Reverse() method. What do i expect from that: // case #1
_context.Set<Customer>()
.AsQueryable()
.OrderBy(c => c.Name)
.ThenByDescending(c => c.BillingAccountNumber)
.ThenBy(c => c.CustomerSignatoryEmail)
.Reverse();
// case #2
_context.Set<Customer>()
.AsQueryable()
.OrderBy(c => c.Name)
.ThenByDescending(c => c.BillingAccountNumber)
.Reverse()
.OrderByDescending(c => c.CustomerSignatoryEmail)
.Reverse(); The OrderBy should be self-explanatory.
That the perfect scenario for some dev to not understand why the code work sometime and note in other scenario. Even if the functionality is documented, many developers will not have the reflex to check it. I wonder why do we need this functionality ? |
@Davilink - Both of the case you posted are different LINQ queries and will generate different results. Reverse affects ordering of everything not just last. And doing an OrderBy on an ordered enumerable will make existing ordering secondary and use the last OrderBy as primary. I would suggest reading up documentation of OrderBy/ThenBy in LINQ enumerables. As for implementation or why we added this functionality: |
@smitpatel Hi, i'm sorry if my message seem to attack someone, it wasn't my intention. English isn't my first language. I was only indicating my concern with the move forward of this implementation. |
@Davilink - Sorry, I did not mean to indicate any attack. I was just indicating that EF Core is just a bridge to translate something already existing in C# to the database. |
We don't translate for any provider (I thought we did for relational).
We never had this functionality in past so not needed for 3.0
The text was updated successfully, but these errors were encountered: