简体   繁体   English

OData - 在$ expand中对集合进行嵌套$过滤

[英]OData - Nested $filter on collection in $expand

Similar to this example I'd like to filter a collection in "Order". 与此示例类似,我想在“订单”中过滤集合。 http://odata.github.io/WebApi/04-03-filter-in-expand/ http://odata.github.io/WebApi/04-03-filter-in-expand/

Let's say we have following model: 假设我们有以下模型:

public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
    public IEnumerable<Order> Orders { get; set; }
}

public class Order
{
    public int Id { get; set; }
    public string Name { get; set; }
    public IEnumerable<Article> Articles { get; set; }
}

public class Article
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Category { get; set; }
}

If I call following URI .../Customers?$expand=Orders($filter=Articles/Category eq 'Cookies') , I get an error saying 如果我调用以下URI ... / Customers?$ expand = Orders($ filter = Articles / Category eq'Cookies') ,我收到错误说

The parent value for a property access of a property 'Category' is not a single value. 属性“类别”的属性访问的父值不是单个值。 Property access can only be applied to a single value. 属性访问只能应用于单个值。

But I can use a construct like: .../Customers?$expand=Orders($filter=Articles/any(a:a/Category eq 'Cookies')) 但我可以使用如下构造: ... / Customers?$ expand = Orders($ filter = Articles / any(a:a / Category eq'Cookies'))

The problem with any or all is, that it is filtering the parant data, based on the children. 任何所有问题都是,它根据子进程过滤了parant数据。 Af "articles" with the "Category" are existing, it will return all articles. 具有“类别”的Af“文章”存在,它将返回所有文章。 But I want to reduce the child-items to show only the articles of category "cookie". 但我想减少子项目只显示“cookie”类别的文章。

I think you need to use two nested different any , if I understand you, you want to filter all the Articles they are in Cookies category, I think you need something like : 我认为你需要使用两个嵌套不同的any ,如果我理解你,你要过滤所有的Articles他们是在Cookies类,我觉得你需要这样的东西:

.../Customers?$filter= Orders/any(o: o/Articles/any(p: p/Category eq 'Cookies'))

it will give you all Customers which have Orders if Orders have cookies Articles . 如果Orders有饼干Articles它会给你所有Orders Customers

Regards. 问候。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM