'HotChocolate sorting on nested collection property
Say a user can have a document set which each set can have one or more files. On the UI I want to allow the user to sort by the file CreatedDate. So when the user clicks on the column header they can sort by date (asc/desc). Given the following how can I configure this sorting behavior HotChocolate side?
public class User
{
public List<DocSet> DocSets {get;set;}
}
public class DocSet
{
public List<File> Files {get;set}
public User User {get;set;}
}
public File
{
public string Name {get;set;}
public DocSet DocSet {get;set;}
public DateTime CreatedDate {get;set;}
}
Here's the HotChocolate query but not sure how to allow sorting (asc/desc) on the File CreatedDate property.
[UseDbContext]
[UseSorting]
public IQueryable<User> GetUser(
[ScopedService] MyDbContext dbContext
) => dbContext.Users;
Solution 1:[1]
try this:
public class DocSet
{
[UseSorting]
public List<File> Files {get;set}
public User User {get;set;}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pascal Senn |
