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

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

  •  27-09-2022
  •  | 
  •  

Frage

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

War es hilfreich?

Lösung

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; }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top