oData:$ expand,$ filter和$ count 1-N Relation

时间:2016-02-10 14:41:49

标签: filter count odata expand

我有两个OData服务(m:DataServiceVersion="2.0"):

  • AACUSTOMERS10M:为客户提供服务,
  • AATRANSACTIONS10M:为客户交易提供服务

在他们之间1..*中定义了<NavigationProperty>关系。

我如何$count所有具有给定FIRSTNAME且至少有一项具有给定TRANSACTION_NAME的交易的客户?

到目前为止,我尝试过(作为一行):

http://.../AACUSTOMERS10M?
  $count
  &$expand=TRANSACTIONS
  &$filter=FIRSTNAME%20%27Maria%27%20
           and%20TRANSACTIONS/TRANSACTION_NAME%20%27New%27

但是我收到了错误

"Illegal query syntax. Segment before '/' is not an entity or complex type."

/ $元数据

<EntityType Name="AACUSTOMERS10MType">
  <Key>
    <PropertyRef Name="ID"/>
  </Key>
  <Property Name="ID" Type="Edm.Int32" Nullable="false"/>
  <Property Name="FIRSTNAME" Type="Edm.String" DefaultValue="" MaxLength="100"/>
  <Property Name="LASTNAME" Type="Edm.String" DefaultValue="" MaxLength="100"/>
  <Property Name="STREET" Type="Edm.String" DefaultValue="" MaxLength="100"/>
  <Property Name="ZIP" Type="Edm.String" DefaultValue="" MaxLength="100"/>
  <Property Name="CITY" Type="Edm.String" DefaultValue="" MaxLength="100"/>
  <Property Name="GENDERNAME" Type="Edm.String" DefaultValue="" MaxLength="100"/>
  <Property Name="AGE" Type="Edm.Byte"/>
  <Property Name="PROFESSIONNAME" Type="Edm.String" DefaultValue="" MaxLength="100"/>
  <Property Name="MARITALSTATUSNAME" Type="Edm.String" DefaultValue="" MaxLength="100"/>
  <Property Name="INCOMENAME" Type="Edm.String" DefaultValue="" MaxLength="100"/>
  <NavigationProperty Name="TRANSACTIONS" Relationship="myTestPack.oData.artificial.CUSTOMER_TRANSACTIONSType" FromRole="AACUSTOMERS10MPrincipal" ToRole="AATRANSACTIONS10MDependent"/>
</EntityType>
<EntityType Name="AATRANSACTIONS10MType">
  <Key>
    <PropertyRef Name="ID"/>
    <PropertyRef Name="CONTRACTNUMBER"/>
    <PropertyRef Name="TRANSACTIONDATE"/>
  </Key>
  <Property Name="ID" Type="Edm.Int32" Nullable="false"/>
  <Property Name="CONTRACTNUMBER" Type="Edm.Int32" Nullable="false"/>
  <Property Name="GESCHAEFTSFELD" Type="Edm.String" MaxLength="100"/>
  <Property Name="BEREICH" Type="Edm.String" MaxLength="100"/>
  <Property Name="AGENT_NAME" Type="Edm.String" MaxLength="201"/>
  <Property Name="TRANSACTIONDATE" Type="Edm.DateTime" Nullable="false"/>
  <Property Name="TRANSACTION_NAME" Type="Edm.String" MaxLength="100"/>
  <Property Name="ENDDATE" Type="Edm.DateTime"/>
  <Property Name="DEPOSITVALUE" Type="Edm.Double"/>
  <Property Name="MONTHLYFEE" Type="Edm.Double"/>
  <Property Name="DELTA" Type="Edm.Double"/>
  <NavigationProperty Name="TRANSACTIONS" Relationship="myTestPack.oData.artificial.CUSTOMER_TRANSACTIONSType" FromRole="AATRANSACTIONS10MDependent" ToRole="AACUSTOMERS10MPrincipal"/>
</EntityType>
<Association Name="CUSTOMER_TRANSACTIONSType">
  <End Type="myTestPack.oData.artificial.AACUSTOMERS10MType" Role="AACUSTOMERS10MPrincipal" Multiplicity="1"/>
  <End Type="myTestPack.oData.artificial.AATRANSACTIONS10MType" Role="AATRANSACTIONS10MDependent" Multiplicity="*"/>
</Association>

1 个答案:

答案 0 :(得分:1)

你可以尝试这个,它应该在OData V4中运行

/ AACUSTOMERS10M?$ count&amp; $ filter = FIRSTNAME eq'Maria'&amp; $ expand = TRANSACTIONS($ filter = TRANSACTION_NAME eq'New')