嵌套收集属性上的hotchocaly排序
假设用户可以有一个文档集,每个文档集可以有一个或多个文件。在 UI 上,我想允许用户按文件 CreatedDate 排序。因此,当用户单击列标题时,他们可以按日期排序(升序/降序)。鉴于以下情况,我如何配置 HotChocolate 端的这种排序行为?
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;}
}
这是 HotChocolate 查询,但不确定如何允许对 File CreatedDate 属性进行排序(asc/desc)。
[UseDbContext]
[UseSorting]
public IQueryable<User> GetUser(
[ScopedService] MyDbContext dbContext
) => dbContext.Users;
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试以下操作:
try this: