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