This is the Patch
method of my OdataController
public async Task<IHttpActionResult> Patch([FromODataUri] int key, Delta<Product> patch)
{
Validate(patch.GetInstance());
Product product = await service.Products.GetAsync(key);
if (product == null)
return NotFound();
patch.Put(product);
try
{
await service.Products.UpdateAsync(product);
}
catch (DbUpdateConcurrencyException)
{
if (!await service.Products.ExistAsync(key))
return NotFound();
else
throw;
}
return Updated(product);
}
My model has a property:
[Timestamp]
public byte[] RowVersion { get; set; }
the DbUpdateConcurrencyException
seems not working at all.
I need to implement concurrency checking mechanism using Etag.
I have seen some examples here.But they are not using Delta in there method.
- How can I check Concurrency using etags?
- Is it possible to implement a custom attribute for concurrency cheacking?
Something Like:
[CustomConcurrencyCheck]
public async Task<IHttpActionResult> Put([FromODataUri] int key, Delta<Product> patch)
{
...
}
Providing a simple example will be highly appreciated.