Sort with Variables tries to instantiate an object from the target collection, fails if no parameterless constructor available #6545
Labels
Area: Data
Issue is related to filtering, sorting, pagination or projections
🐛 bug
Something isn't working
🌶️ hot chocolate
Is there an existing issue for this?
Product
Hot Chocolate
Describe the bug
I have a business backend that deals, among other entities, with subjects and their addresses. In the database, handled via Entity Framework Core 7, there is a relation between the subject and its addresses, so that inside the Subject entity there is an "Addresses" navigation property which is defined as an ICollection
. Both classes have no parameterless constructor to fill non-nullable property values.When returning an IQueryable to HotChocolate, I have the query set up like this:
The readRepository wraps and ultimately returns the DbSet from Entity Framework, just mixing in a .Where condition on the DeletionDate field.
For the purpose of the bug, I don't think filtering middleware is an issue; the sorting middleware is configured with these settings:
In this way, a virtual "legalResidentialAddress" field is added to the GraphQL schema, and it is supposed to be able to be used for sorting.
Indeed when the query is like this:
the expected results are received.
But when the query includes variables, like this:
An exception is raised and no errors are returned. Exception details and stacktrace is below.
I don't expect the difference between using and not using variables to produce the instantiation of an object from the target class of the sorting collection; why is it happening? Is a parameterless constructor actually needed?
Steps to reproduce
Due to the complexity of producing a sample showcase github repo, it will be added if the above description is not enough to understand the issue clearly.
Relevant log output
Additional Context?
No response
Version
13.2.1
The text was updated successfully, but these errors were encountered: