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

Query: compilation error for query with Last() in a subquery #8582

Closed
maumar opened this issue May 25, 2017 · 2 comments · Fixed by #17766
Closed

Query: compilation error for query with Last() in a subquery #8582

maumar opened this issue May 25, 2017 · 2 comments · Fixed by #17766
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. punted-for-2.0 punted-for-2.1 type-bug
Milestone

Comments

@maumar
Copy link
Contributor

maumar commented May 25, 2017

query:

context.Gears
.OrderBy(g => g.Nickname)
.Where(g => !g.HasSoulPatch && g.Weapons.Distinct().Last().IsAutomatic)

throws:

Expression of type 'System.Func`2[Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel.Gear,System.Collections.Generic.IEnumerable`1[System.Boolean]]' cannot be used for parameter of type 'System.Func`2[Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel.Gear,System.Boolean]' of method 'System.Collections.Generic.IEnumerable`1[Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel.Gear] _Where[Gear](System.Collections.Generic.IEnumerable`1[Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel.Gear], System.Func`2[Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel.Gear,System.Boolean])'

This happens because in ResultOperatorHandler.HandleLast we push last below select (needed so that we don't track unnecessary elements). However, if last is in a subquery, rather than being the final result operator this changes cardinality of that subquery, which leads to the exception.

@ajcvickers ajcvickers added this to the 2.0.0 milestone May 26, 2017
@ajcvickers ajcvickers modified the milestones: Backlog, 2.0.0 May 26, 2017
@ajcvickers ajcvickers modified the milestones: 2.1.0, Backlog Sep 7, 2017
@ajcvickers ajcvickers modified the milestones: 2.1.0-preview1, 2.1.0 Jan 17, 2018
@divega divega modified the milestones: 2.1.0-preview2, 2.1.0 Apr 2, 2018
@ajcvickers ajcvickers modified the milestones: 2.1.0, Backlog Apr 10, 2018
@smitpatel
Copy link
Contributor

Not needed. The code has changed and we don't allow Last with order by.

@smitpatel
Copy link
Contributor

smitpatel commented Sep 4, 2019

Test coverage #17607

@smitpatel smitpatel removed this from the Backlog milestone Sep 4, 2019
@smitpatel smitpatel added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed closed-not-needed labels Sep 10, 2019
@smitpatel smitpatel added this to the 3.0.0 milestone Sep 10, 2019
@smitpatel smitpatel self-assigned this Sep 10, 2019
smitpatel added a commit that referenced this issue Sep 11, 2019
Covers EFCore.Specs.Tests Query folder

Resolves #8366
Resolves #8582
Resolves #8722
Resolves #9007
Resolves #9254
Resolves #12574
Resolves #12579
Resolves #12598
Resolves #12786
Resolves #12787
Resolves #12794
Resolves #12806
Resolves #12827
Resolves #12873
Resolves #14900
Resolves #15862
Resolves #16157
Resolves #17240
Resolves #17243


Close #12889
Close #17243
smitpatel added a commit that referenced this issue Sep 11, 2019
Covers EFCore.Specs.Tests Query folder

Resolves #8366
Resolves #8582
Resolves #8722
Resolves #9007
Resolves #9254
Resolves #12574
Resolves #12579
Resolves #12598
Resolves #12786
Resolves #12787
Resolves #12794
Resolves #12806
Resolves #12827
Resolves #12873
Resolves #14900
Resolves #15862
Resolves #16157
Resolves #17240


Close #12889
Close #17243
smitpatel added a commit that referenced this issue Sep 11, 2019
Covers EFCore.Specs.Tests Query folder

Resolves #8366
Resolves #8582
Resolves #8722
Resolves #9007
Resolves #9254
Resolves #12574
Resolves #12579
Resolves #12598
Resolves #12786
Resolves #12787
Resolves #12794
Resolves #12806
Resolves #12827
Resolves #12873
Resolves #14900
Resolves #15862
Resolves #16157
Resolves #17240


Close #12889
Close #17243
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. punted-for-2.0 punted-for-2.1 type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants