Skip to content
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

Group by + orderby query no longer working #18077

Closed
Looooooka opened this issue Sep 26, 2019 · 1 comment
Closed

Group by + orderby query no longer working #18077

Looooooka opened this issue Sep 26, 2019 · 1 comment

Comments

@Looooooka
Copy link

Looooooka commented Sep 26, 2019

This query worked fine in EF Core 2
datacontext.data_Rewards.GroupBy(x => x.RewardGameType, (key, g) => g.OrderByDescending(e => e.RewardPriority).FirstOrDefault()).ToList();``
in EF Core 3 it fails with

nvalidOperationException: The LINQ expression 'OrderByDescending<data_Rewards, int>( source: GroupByShaperExpression: KeySelector: d.RewardGameType, ElementSelector:EntityShaperExpression: EntityType: data_Rewards ValueBufferExpression: ProjectionBindingExpression: EmptyProjectionMember IsNullable: False , keySelector: (e) => e.RewardPriority)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

The original query produced an orderby SQL query and another group by query.
Is there a way to at least turn back this default behavior or does one simply have to fix all the queries and make them work so they're correctly evaluated in sql server in a sinqle query?

I did rewrite this one but...I'm just afraid that a lot of queries might now just fail after updating

@smitpatel
Copy link
Member

By design https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/breaking-changes#linq-queries-are-no-longer-evaluated-on-the-client

See #17068 & #13805

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants