How do you use optimistic concurrency with WebAPI OData controller

asp.net asp.net-web-api asp.net-web-api-odata entity-framework-6 odata

Question

I have a WebAPI OData controller that updates my entity partially utilizing the Delta.

I've included a Version field in my entity framework model. With its concurrency mode set to Fixed (using database first), Entity Framework's mapping of this rowversion from the SQL Server database to a byte array.

Using an outdated value for the Version field, I'm using Fiddler to send back a partial update. When I patch my altered fields over the top of the current record from my context, the values in the Version column are changed without producing an error, and when I save changes on my context, everything is saved without error. The thing that is being saved has not been detached from the context, therefore this is obviously expected. However, how can I create optimistic concurrency with a Delta?

Entity Framework 6.0.1 and OData 5.6.0 are the absolute latest versions of everything I'm using (or were right before Christmas).

public IHttpActionResult Put([FromODataUri]int key, [FromBody]Delta<Job> delta)
{
    using (var tran = new TransactionScope())
    {
        Job j = this._context.Jobs.SingleOrDefault(x => x.JobId == key);

        delta.Patch(j);

        this._context.SaveChanges();

        tran.Complete();

        return Ok(j);
    }
}

Thanks

1
2
1/6/2014 3:13:45 PM

Popular Answer

ZZZ_tmp
3
8/4/2015 6:20:30 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow