问题描述
我是热巧克力的新手,我有一个我无法弄清楚的过滤用例。
我的产品存储库中有此功能可返回产品数据。
public IQueryable<Product> GetProducts()
{
return _context.Products.Where(e=>e.indx == null);
}
如果用户过滤产品类别中的字段品牌,我想更改查询,使其不选择 Where(e=>e.indx==null)。当用户在现场品牌或产品类型或两者上执行此操作时,我需要执行此操作。
解决方法
尝试这样的事情:
[UseProjection]
[UseFiltering]
public IQueryable<Customer> GetAll([Service] NorthWindDBContext dBContext)
{
return dBContext.Customers.AsQueryable();
}
这允许我编写查询,例如:
query {
customers(where: {
customerId: {
eq: "ALFKI"
}
}) {
customerId
contactName
companyName
address
}
}