我正在尝试深入了解OData,并使用以下元数据创建了一项服务:
<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" Version="1.0">
<edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="2.0">
<Schema xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://schemas.microsoft.com/ado/2008/09/edm" Namespace="HelloOdata.library">
<EntityType Name="booksType">
<Key>
<PropertyRef Name="title"/>
</Key>
<Property Name="title" Type="Edm.String" Nullable="false" MaxLength="100"/>
<Property Name="ISBN" Type="Edm.String" MaxLength="100"/>
<Property Name="editions" Type="Edm.Int32"/>
<NavigationProperty Name="Author" Relationship="HelloOdata.library.WroteType" FromRole="booksPrincipal" ToRole="writersDependent"/>
</EntityType>
<EntityType Name="writersType">
<Key>
<PropertyRef Name="name"/>
<PropertyRef Name="birth"/>
</Key>
<Property Name="name" Type="Edm.String" Nullable="false" MaxLength="100"/>
<Property Name="birth" Type="Edm.DateTime" Nullable="false"/>
<NavigationProperty Name="Titles" Relationship="HelloOdata.library.BooksType" FromRole="writersPrincipal" ToRole="booksDependent"/>
</EntityType>
<Association Name="WroteType">
<End Type="HelloOdata.library.booksType" Role="booksPrincipal" Multiplicity="*"/>
<End Type="HelloOdata.library.writersType" Role="writersDependent" Multiplicity="1"/>
</Association>
<Association Name="BooksType">
<End Type="HelloOdata.library.writersType" Role="writersPrincipal" Multiplicity="1"/>
<End Type="HelloOdata.library.booksType" Role="booksDependent" Multiplicity="*"/>
</Association>
<EntityContainer Name="library" m:IsDefaultEntityContainer="true">
<EntitySet Name="books" EntityType="HelloOdata.library.booksType"/>
<EntitySet Name="writers" EntityType="HelloOdata.library.writersType"/>
<AssociationSet Name="Wrote" Association="HelloOdata.library.WroteType">
<End Role="booksPrincipal" EntitySet="books"/>
<End Role="writersDependent" EntitySet="writers"/>
</AssociationSet>
<AssociationSet Name="Books" Association="HelloOdata.library.BooksType">
<End Role="writersPrincipal" EntitySet="writers"/>
<End Role="booksDependent" EntitySet="books"/>
</AssociationSet>
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
您是否知道如何在Write和Book之间创建链接?我试图阅读OData文档中的示例,但我没有成功和我的尝试。我正在使用OData数据协议v2。
谢谢。 巴勃罗
我已经创建了这个POST请求:
POST /HelloOdata/library.xsodata/books('HAPI%20Hana%20Integration%20Test%20Volume%201')/$links/Author HTTP/1.1
Host: xxxxx
DataServiceVersion: 1.0
MaxDataServiceVersion: 2.0
Content-Type: application/xml
<uri xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices">
http://host-service/HelloOdata/library.xsodata/writers(name='Robert%20Kingst',birth=datetime'2008-04-08T00:00:00.0000000')
</uri>
我收到了以下回复:
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code />
<message xml:lang="en-US">The URI is not valid for POST operation. The URI must point to an entity set for POST operations.</message>
</error>
答案 0 :(得分:0)
假设您要链接作者&#34; Charles Dickens&#34;在书中&#34; Oliver Twist&#34;,然后您向您的服务发送POST请求:
POST http://host/service/booksType('Oliver Twist')/$links/Author
<uri xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices">
http://host/service/writersType(name='Charles Dickens',birth='1812-02-07T00:00:00')
</uri>
答案 1 :(得分:0)
由于Author不是集合,请尝试将方法从POST更改为PUT。