Is there automatic ETag handling in OData with WebApi 2 and Entity Framework (code first)?

StackOverflow https://stackoverflow.com/questions/21099336

  •  27-09-2022
  •  | 
  •  

문제

WCF Data Services with Entity Framework is automatically handling ETag headers (defined using [ETagAttribute] or automagically from [TimestampAttribute]).

I created WebApi2 OData controller from scaffolding. My entity have a valid timestamp (rowversion) property. However I don't see the ETag header in http response.

How can I enable valid ETag handling with OData + Web Api 2 + EF 6?

Thanks, Stefan

도움이 되었습니까?

해결책

WebAPI v2.2 supports OData v4 and has support for ETags. See the "Support for ETags" section in this MSDN blog post. You can use either the [TimeStamp] attribute or the [ConcurrencyCheck] attribute but not both. An example property on your model would look like:

[Timestamp] 
public byte[] RowVersion { get; set; }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top