Skip to content

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

@maumar

Description

@maumar

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions