Skip to content

ToPageAsync() (QueryHelpers.EnsureOrderPropsAreSelected) attempts to select Order properties that it should not #8262

Description

@Tommsy64

Product

Green Donut

Version

16.0.14-p.1

Link to minimal reproduction

https://github.com/Tommsy64/HotChocolate-IssueReproductions/tree/f817b8b9696a7079997007245d3c628902170975

Steps to reproduce

  1. dotnet run
  2. Run the following GraphQL query:
query {
  speakers {
    nodes {
      name
    }
  }
}

Exception is thrown:

Property 'System.String Name2' is not defined for type 'HotChocolateIssueReproduction.Types.SpeakerDto' (Parameter 'property')

The same exception is also thrown by the speakers2 field, which uses [UsePaging] instead of [UseConnection].

What is expected?

When OrderBy expressions exist in the Selector, they should not be automatically selected by QueryHelpers.EnsureOrderPropsAreSelected();

What is actually happening?

The following expression contains an OrderBy that causes QueryHelpers.EnsureOrderPropsAreSelected to attempt to select OtherProperty, which does not exist on the Dto.

e => new Dto
        {
            Id = e.Id,
            NotWorking = e.ListOfObjects.OrderByDescending(l => l.OtherProperty).FirstOrDefault()
        });

Relevant log output

message: Property 'System.String Name2' is not defined for type
	'HotChocolateIssueReproduction.Types.SpeakerDto' (Parameter 'property')
  at System.Linq.Expressions.Expression.Property(Expression expression, PropertyInfo property)
  at GreenDonut.Data.Expressions.QueryHelpers.AddPropertiesVisitorRewriter.VisitMemberInit(MemberInitExpression node)
  at GreenDonut.Data.Expressions.QueryHelpers.AddPropertiesInSelector[T](Expression`1 selector, List`1 properties)
  at GreenDonut.Data.Expressions.QueryHelpers.EnsureOrderPropsAreSelected[T](IQueryable`1 query)
  at GreenDonut.Data.PagingQueryableExtensions.ToPageAsync[T](IQueryable`1 source, PagingArguments arguments, Boolean includeTotalCount, CancellationToken cancellationToken)
  at GreenDonut.Data.PagingQueryableExtensions.ToPageAsync[T](IQueryable`1 source, PagingArguments arguments, CancellationToken cancellationToken)

Additional context

Issue initially submitted for version 15.1.3 but still reproduces in 16.0.14-p.1.

Activity

  1. added theissue type on Apr 24, 2025
  2. changed the issue type fromtoon May 20, 2025
  3. tomachristian commented on Sep 5, 2025

    @tomachristian

    Having the same exact issue.

  4. Tommsy64 commented on Jun 3, 2026

    @Tommsy64
    ContributorAuthor

    Coming back to this a year later: It still reproduces on the latest preview, 16.0.14-p.1, and I've updated the issue body and reproduction to match.

    I've also simplified the reproduction so it no longer needs a live database.

  5. michaelstaib commented on Jun 3, 2026

    @michaelstaib
    Member

    Let me have a look at this one.

  6. self-assigned this
    on Jun 3, 2026
  7. Tommsy64 commented on Jun 3, 2026

    @Tommsy64
    ContributorAuthor

    I had already started digging into this yesterday, so I went ahead and opened #9840. Feel free to build on it directly or close it if you have a different approach in mind.

  8. added a commit that references this issue on Jul 11, 2026
    63ba715
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions