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

У меня есть две службы 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 ответ

Вы можете попробовать это, это должно работать в OData V4

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

Другие вопросы по тегам