1

私は複合主キーを持つエンティティを持っている、と私は使用しての単一のインスタンスを取得することができます。コンポジット主キーでエンティティをパッチングする方法は?

GET https://example.com/service/Contacts(Foo=3,Bar=18) 

どのように私はそれのインスタンスを更新することができますか?私は、同じアドレス使用してパッチを試してみました:

PATCH https://example.com/service/Contacts(Foo=3,Bar=18) 

をしかし、私は次のエラーを取得:

{ 
    "error" : { 
     "code" : "", 
     "message" : "The request is invalid.", 
     "innererror" : { 
      "message" : "key : Expected literal type token but found token 'Foo'.\r\n", 
      "type" : "", 
      "stacktrace" : "" 
     } 
    } 
} 

このエラーは何を意味するのか?

私はまた、プロパティ名なしで試してみましたが、私は別のエラーを取得:

PATCH https://example.com/service/Contacts(3,18) 

Cannot create an abstract class. Description: An unhandled exception occurred during the execution of the current web request. Please review the stacktrace for more information about the error and where it originated in the code.

私はこのケースでPATCHを行うことができますどのように任意のアイデアを?

ありがとうございます。

答えて

0

は私が遅すぎる相手にしていてもよいが、ここでは、このマニュアルのモデルのセットアップでのOData V6(System.Web.OData)とEntity Frameworkのあることを、PATCH

注意のために行きます。私は、ODataの以前のバージョンはこれをそのまま受け入れていなかったと思います。

コントローラでは、アクションパッチに 'key' + {ModelPropertyName}で構成された引数が必要です。あなたのモデルがプロパティーFooBarを持っていることを考慮すると、コントローラのアクションは以下のようになるはずです。

public async Task<IHttpActionResult> Patch([FromODataUri] int keyFoo, [FromODataUri] int keyBar, Delta<FooBarModel> modelDelta) 

引数の大文字と小文字は関係ありません。必要に応じて、KeyFoOのように設定できます。しかし実際にはURL上で重要です。

PATCH https://example.com/service/Contacts(Foo=3,Bar=18)

ここではケーシングは問題です。これは問題ではありません

PATCH https://example.com/service/Contacts(foo=3,bar=18)

注文、これは

PATCH https://example.com/service/Contacts(Bar=18 , Foo=3)

に動作します。これは動作しません動作しないでしょう

PATCH https://example.com/service/Contacts(3,18)

関連する問題