私は以下のコードを持っています:
public class MyPatchController : EntitySetController<Books , int>
{
protected override Books PatchEntity(int key, Delta<Books> patch)
{
var Book = db.books.FirstOrDefault(p => p.ID== key);
if (Book == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
patch.Patch(Book);
db.SaveChanges();
return Book ;
}
}
Books エンティティには AuthorID 外部キーがあります。ただし、クライアントは作成者の名前 (ID ではない) を使用して PATCH を実行する必要があり、json を次のように送信します。
{AuthorName : "Joe Smith"}
AuthorName は Book のモデルではありません。
私がやろうとしているのは、linq を使用して authorID を検索することですが、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="3.0" m:MaxDataServiceVersion="3.0">
<Schema xmlns="http://schemas.microsoft.com/ado/2009/11/edm" Namespace="Store.Models">
<EntityType Name="BOOK">
<Key>
<PropertyRef Name="BOOK_ID"/>
</Key>
<Property Name="BOOK_ID" Type="Edm.Int32" Nullable="false"/>
<Property Name="BOOK_NAME" Type="Edm.String"/>
<Property Name="AUTHOR_ID" Type="Edm.Int32"/>
</EntityType>
<EntityType Name="AUTHOR">
<Key>
<PropertyRef Name="AUTHOR_ID"/>
</Key>
<Property Name="AUTHOR_ID" Type="Edm.Int32" Nullable="false"/>
<Property Name="AUTHOR_NAME" Type="Edm.String"/>
</EntityType>
</Schema>
<Schema xmlns="http://schemas.microsoft.com/ado/2009/11/edm" Namespace="Default">
<EntityContainer Name="Container" m:IsDefaultEntityContainer="true">
<EntitySet Name="Author" EntityType="Store.Models.Author"/>
<EntitySet Name="Book" EntityType="Store.Models.Book"/>
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>