You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Query: Property binding on the result entity from grouping.First #26753
MyField is mapped property but in translation we see a shaped query on which we have to bind rather than entity reference so we fail to bind and throw error that OrderBy couldn't be translated. (Same goes for Select or any other operation which tries to bind property)
I ran the query with OrderBy in release/6.0 branch and it failed for me with client eval error. Select also caused client eval error rather than a random exception. Please provide a runnable repro if you are seeing otherwise.
I see why - it was getting applied before the GroupBy:
dbset.OrderBy(p=> p.MyField).GroupBy(p=> new { MyField = p.MyField, MyOtherField = p.MyOtherField}).Select(p=> p.First())
@LeaFrock Generically - do as much as you can before the GroupBy and then anything that can't, client-side the effort after.
They are targeting numerous fixes for GroupBy in 7.0, but for now, it's workarounds.
Right off the bat I can see this after the GroupBy - that alone will throw the error you're getting: .OrderByDescending(p => p.Age)
Activity
OpenSpacesAndPlaces commentedon Nov 18, 2021
Noting for my use case - pre-OrderBy worked ok (I guess that's a workaround of sorts).
Count or Select Shaping specifically were the issues:
GroupBy(p=> new { MyField = p.MyField, MyOtherField = p.MyOtherField}).Select(p=> p.First()).Count()
GroupBy(p=> new { MyField = p.MyField, MyOtherField = p.MyOtherField}).Select(p=> p.First()).Select(p=>p.MyField)
smitpatel commentedon Nov 18, 2021
I ran the query with OrderBy in release/6.0 branch and it failed for me with client eval error. Select also caused client eval error rather than a random exception. Please provide a runnable repro if you are seeing otherwise.
OpenSpacesAndPlaces commentedon Nov 18, 2021
I see why - it was getting applied before the GroupBy:
dbset.OrderBy(p=> p.MyField).GroupBy(p=> new { MyField = p.MyField, MyOtherField = p.MyOtherField}).Select(p=> p.First())
LeaFrock commentedon Feb 23, 2022
Another use case of mine,
What I want to do,
CountryAge(but < 25) of each groupId,NameAgeSo, My codes are like below,
But now EF Core throws
InvalidOperationException: ... could not be translated. ....OpenSpacesAndPlaces commentedon Feb 23, 2022
@LeaFrock Generically - do as much as you can before the GroupBy and then anything that can't, client-side the effort after.
They are targeting numerous fixes for GroupBy in 7.0, but for now, it's workarounds.
Right off the bat I can see this after the GroupBy - that alone will throw the error you're getting:
.OrderByDescending(p => p.Age)