【发布时间】:2019-10-08 21:02:55
【问题描述】:
与此示例类似,我想过滤“订单”中的集合。 http://odata.github.io/WebApi/04-03-filter-in-expand/
假设我们有以下模型:
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; }
}
如果我调用以下 URI .../Customers?$expand=Orders($filter=Articles/Category eq 'Cookies'),我会收到一条错误消息
属性“类别”的属性访问的父值不是 单个值。属性访问只能应用于单个值。
但我可以使用如下构造:.../Customers?$expand=Orders($filter=Articles/any(a:a/Category eq 'Cookies'))
any 或 all 的问题在于,它会根据子级过滤父数据。如果存在带有“类别”的“文章”,它将返回所有文章。但我想减少子项以仅显示“cookie”类别的文章。
【问题讨论】: