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.

어떤 생각을?

감사합니다.

답변

0

것은 내가 파티에 너무 늦게 모르지만,이 수동 모델 설정과 하나로, OData V6 (System.Web.OData)와 엔티티 프레임 워크는 것을 여기가, 패치

주 이동 될 수 있습니다. 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)