c# - 过滤 GraphQL HotChocolate 上的 EF Core Navigation 属性
问题描述
我正在使用带有 EF Core 的 HotChocolate (11.2.2) 并且想要过滤子属性。根据 GraphQL 文档,这应该可以通过在导航属性上使用 filter 关键字来实现,但 HotChocolate 只是失败了。
我的架构:
type A {
Name: string,
RefTo: [B]
}
type B {
TypeName: string,
Value: int
}
这是由 EF 支持的,我为IQueryable<A>
HotChocolate 提供了一个。
[UsePaging]
[UseProjection]
[UseFiltering]
[UseSorting]
public IQueryable<A> GetAs([Service] Context db) => db.As.AsSingleQuery().AsNoTrackingWithIdentityResolution();
现在我只想包括那些等于这样B
的 s :TypeName
"ExampleType"
query {
As {
Name,
RefTo(where: { TypeName: { eq: "ExampleType" } })
{
TypeName,
Value
}
}
}
但 HotChcolate 似乎并不理解这一点,并说:
字段“A.RefTo”.validation 上的未知参数“where”
是否可以使用 EF Core 模型过滤导航属性?
解决方案
您也必须向 RefTo 添加过滤
[UseFiltering]
public ICollection<A> RefTo {get; set;}
推荐阅读
- python-3.x - 计算两个熊猫列之间向量的余弦相似度?
- elasticsearch - 使用 logstash 解析 json 数组字符串
- docker - 将 Kubernetes pod 限制为一个进程
- php - 以相同的刀片显示表单和结果的结果 - laravel
- django - Django 管理模板在服务器和本地之间看起来不同
- javascript - 如何在没有jquery的情况下更改文档滚动速度
- python - 比较 CSV 文件并将重复项返回到新的 CSV 文件
- c# - 单击后如何禁用按钮。换句话说,有一个只能点击一次的按钮
- ios - 在 TabBar SwiftUI 中更改选项卡选择颜色
- angular - 数组数据未在第二次路由到组件时更新