Skip to content

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

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

Open
Tommsy64 opened this issue Apr 24, 2025 · 0 comments

Comments

@Tommsy64
Copy link

Tommsy64 commented Apr 24, 2025

Product

Green Donut

Version

15.1.3

Link to minimal reproduction

https://github.com/Tommsy64/HotChocolate-IssueReproductions/tree/88256b4db5a1a60196bb23e249da85dec8732a66

Steps to reproduce

  1. docker compose up -d to start the ephemeral database (no persistant volume, defaults to port 5433).
  2. dotnet ef database update
  3. dotnet run
  4. 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')

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')
  stackTrace: "   at System.Linq.Expressions.Expression.Property(Expression
	expression, PropertyInfo property)\r

	\   at
	GreenDonut.Data.Expressions.QueryHelpers.AddPropertiesVisitorRewriter.V\
	isitMemberInit(MemberInitExpression node)\r

	\   at
	GreenDonut.Data.Expressions.QueryHelpers.AddPropertiesInSelector[T](Exp\
	ression`1 selector, List`1 properties)\r

	\   at
	GreenDonut.Data.Expressions.QueryHelpers.EnsureOrderPropsAreSelected[T]\
	(IQueryable`1 query)\r

	\   at
	GreenDonut.Data.PagingQueryableExtensions.ToPageAsync[T](IQueryable`1
	source, PagingArguments arguments, Boolean includeTotalCount,
	CancellationToken cancellationToken)\r

	\   at
	GreenDonut.Data.PagingQueryableExtensions.ToPageAsync[T](IQueryable`1
	source, PagingArguments arguments, CancellationToken
	cancellationToken)\r

Additional context

No response

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

1 participant