本文介绍了OData $筛选项目在$ expand中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经提供了一些Web服务来访问信息。

我尝试展开一个节点的第一件事。我已经用下面的代码成功完成了:

  http://www.domain.com/ODataService/WorkService.svc/CaseStudies ?format = json& $ expand = ServiceOfferings 

现在我想过滤ServiceOfferingID, ServiceOfferings。
如何针对扩展集合使用过滤选项

  http://www.domain.com/ODataService/WorkService .svc / CaseStudies?format = json& $ expand = ServiceOfferings& $ filter = ServiceOfferings.ServiceOfferingID eq 127 

但它不工作。什么是正确的做法相同

解决方案

您需要编写的查询取决于。



以下是一些使用public 。



一个订单总是由一个客户完成。



查找具有特定名称的客户所下的订单:
。这相当于Dhawal的答案。


客户可以发出很多订单。



使用 全部任何

指定您是否希望至少有一个订单或所有订单符合您的条件。
$ b


  1. 找到客户,或者更多订单已经由特定员工处理:

  2. 查找长时间没有订购任何商品的顾客:

您可以调用并检查NavigationProperty元素,订单
Relationship =NorthwindModel.FK_Orders_Customers
ToRole =订单
FromRole =客户/>

然后,查找与该名称的关联,您将找到基数:

 < Association Name =FK_Orders_Customers> 
< End
Type =NorthwindModel.Customer
Role =Customers
Multiplicity =0..1/>
< End
Type =NorthwindModel.Order
Role =Orders
Multiplicity =*/>
...

导航一对多关系:,会给你:属性访问属性的父值EmployeeID不是一个单一的值,属性访问只能应用于一个单一的值。



导航与所有人的多对一关系或者像,会给你:
Any / All may只有在收集后才能使用。


I have given some web services to access informations.

The first thing that i have tries to expand a node . And i have done that successfully with following code

http://www.domain.com/ODataService/WorkService.svc/CaseStudies?format=json&$expand=ServiceOfferings

Now i want to filter ServiceOfferingID that i will get when expanding ServiceOfferings .How can use filter option against a expanded collection

http://www.domain.com/ODataService/WorkService.svc/CaseStudies?format=json&$expand=ServiceOfferings&$filter=ServiceOfferings.ServiceOfferingID eq 127 

But its not working. What is right way to do the same

解决方案

The query you'll need to write depends on the cardinality of the expanded collection.

Here are some examples that use the public sample OData Northwind service, provided by odata.org.

An order is always done by exactly one customer.

Find the orders made by a customer with a specific name:http://services.odata.org/V3/Northwind/Northwind.svc/Orders?$expand=Customer&$filter=Customer/CompanyName eq 'Vins et alcools Chevalier'. This is equivalent to the answer of Dhawal.

A customer can issue many orders.

Use the quantifiers all or any to specify whether you want at least one, or all of the orders to obey your conditions.

  1. Find customers for which one or more orders have been processed by a specific employee:http://services.odata.org/V3/Northwind/Northwind.svc/Customers?$expand=Orders&$filter=Orders/any(o: o/EmployeeID eq 9)
  2. Find customers that haven't ordered anything for a long time:http://services.odata.org/V3/Northwind/Northwind.svc/Customers?$expand=Orders&$filter=Orders/all(o: o/OrderDate lt DateTime'1997-01-01')

You can call http://services.odata.org/V3/Northwind/Northwind.svc/$metadata and inspect the NavigationProperty elements, to see which relations exist.

<NavigationProperty Name="Orders" 
    Relationship="NorthwindModel.FK_Orders_Customers" 
    ToRole="Orders" 
    FromRole="Customers"/>

Then, look for an association with that name and you'll find the cardinality:

<Association Name="FK_Orders_Customers">
    <End 
         Type="NorthwindModel.Customer" 
         Role="Customers" 
         Multiplicity="0..1"/>
    <End 
         Type="NorthwindModel.Order" 
         Role="Orders" 
         Multiplicity="*"/>
    ...

Navigating a one-to-many relationship like this: http://services.odata.org/V3/Northwind/Northwind.svc/Customers?$expand=Orders&$filter=Orders/EmployeeID eq 9, will give you: "The parent value for a property access of a property 'EmployeeID' is not a single value. Property access can only be applied to a single value."

Navigating a many-to-one relationship with all or any, like http://services.odata.org/V3/Northwind/Northwind.svc/Orders?$expand=Customer&$filter=Customer/any(c: c/CompanyName eq 'Vins et alcools Chevalier'), will give you:"Any/All may only be used following a collection."

这篇关于OData $筛选项目在$ expand中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 16:07