[英]OData v2 filter by property of $expanded entity
I am using $expand
to enhance an OData SharePoint REST query, and I would like to $filter
on one of the properties of the expanded entity. 我使用
$expand
来增强OData SharePoint REST查询,我想对扩展实体的其中一个属性进行$filter
。 However, I can't find any documentation on the correct syntax for this. 但是,我找不到任何关于正确语法的文档。 I've found a few spots that might suggest using Entity/property, but after trying that, I fail with:
我发现了一些可能建议使用Entity / property的地方,但在尝试之后,我失败了:
Query: 查询:
_vti_bin/listdata.svc/Posts?$expand=Category&$filter=substring(\"Featured Article\",Category/Title) eq false and year(Published) lt " +year+1+ " and month(Published) lt " +month+1+ " or day(Published) lt " +day+1+ " and ApprovalStatus eq '0'&$select=Title,Published,Category,ApprovalStatus&$orderby=Published desc"
Which returns: 哪个回报:
syntax error '\"' at position 10.
How would I filter based on the Title of the Category entity, when Category is a high level, and it's Title property is a sub-level? 当Category为高级别时,我将如何根据类别实体的标题进行过滤,并且它的Title属性是子级别?
The filter on navigation entities is independent of the expand. 导航实体上的过滤器与扩展无关。
If the navigation property is a not collection (1:1 relation) 如果导航属性是非集合(1:1关系)
You can filter with type/property, here is an example to search for all orders that are made by customers with some id: http://services.odata.org/V2/Northwind/Northwind.svc/Orders?$filter=Customer/CustomerID%20eq%20%27ANATR%27 您可以使用类型/属性进行过滤,这是一个示例,用于搜索具有一些ID的客户所做的所有订单: http : //services.odata.org/V2/Northwind/Northwind.svc/Orders?$ filter = Customer /客户id%20当量%20%27ANATR%27
If the navigation property is a collection (1:N relation) : 如果导航属性是集合(1:N关系) :
OData Version 2 : when the expanded entity is an entity collection, you cannot search on both the expanded and the target entity. OData版本2 :当扩展实体是实体集合时,您无法同时搜索扩展实体和目标实体。 For example you cannot do that query http://services.odata.org/V4/Northwind/Northwind.svc/Customers?$expand=Orders&$filter=Orders/ShipCity%20eq%20%27Berlin%27
例如, 你不能这样查询 http://services.odata.org/V4/Northwind/Northwind.svc/Customers?$expand=Orders&$filter=Orders/ShipCity%20eq%20%27Berlin%27
A work around might be to flip the query (to selecting the orders instead of customers - each order has 1 cutomer): http://services.odata.org/V2/Northwind/Northwind.svc/Orders?$filter=ShipCity%20eq%20%27Berlin%27&$expand=Customer but then you could get duplicate customers (your actual target entity). 解决方法可能是翻转查询(选择订单而不是客户 - 每个订单有1个cutomer): http ://services.odata.org/V2/Northwind/Northwind.svc/Orders?$ filter?ShipCity% 20eq%20%27Berlin%27&$ expand =客户但您可以获得重复客户(您的实际目标实体)。
OData Version 3 You might consider to use a custom query option ( http://www.odata.org/documentation/odata-version-3-0/url-conventions/ ). OData版本3您可以考虑使用自定义查询选项( http://www.odata.org/documentation/odata-version-3-0/url-conventions/ )。
OData Version 4 : you can do a filter with the any construct: http://services.odata.org/V4/Northwind/Northwind.svc/Customers ?$filter=Country%20eq%20%27Germany%27%20and%20Orders/any(o:o/ShipCity%20eq%20%27Berlin%27) OData版本4 :您可以使用任何构造进行过滤: http ://services.odata.org/V4/Northwind/Northwind.svc/Customers?$ filter = Country%20eq%20%27Germany%27%20and%20Orders /任何(O:O /货主国家%20当量%20%27Berlin%27)
It looks like the problem is the slash-escaped double quote and that you're using substring
instead of substringof
. 看起来问题是斜线转义双引号,而你使用的是
substring
而不是substringof
。
Does it work if you use single quotes instead? 如果你改用单引号,它会起作用吗? Or did you want to literally match the double-quote character?
或者你想要真正匹配双引号字符? (If that's the case, I think you can just leave the double quote unescaped inside the single quotes)
(如果是这种情况,我认为你可以将双引号保留在单引号内)
_vti_bin/listdata.svc/Posts?$expand=Category&$filter=substringof('Featured Article',Category/Title) eq false
or 要么
_vti_bin/listdata.svc/Posts?$expand=Category&$filter=substringof('"Featured Article"',Category/Title) eq false
As an example on a public service, take a look at this query: 作为公共服务的示例,请查看此查询:
http://services.odata.org/Northwind/Northwind.svc/Products?$filter=substringof('Bev', Category/CategoryName) eq true
As far as documentation for the OData query syntax, I recommend taking a look at this page: http://www.odata.org/documentation/odata-v3-documentation/url-conventions 至于OData查询语法的文档,我建议看一下这个页面: http : //www.odata.org/documentation/odata-v3-documentation/url-conventions
In the filter section there are a fair number of examples you can use for guidance. 在过滤器部分中,您可以使用相当多的示例作为指导。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.