Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing PATCH with Delta<T> with JSON Formatter
    primarykey
    data
    text
    <p>I have installed the OData library, but only to gain access to Delta for making PATCH usable for WebAPI. It is kinda working, but not for types like decimal and int. I understand this is due to the JSON Formatter, and not specifically Delta but is there a workaround or a fix (or workaround) that can be applied to this to get it to work. </p> <p>I know Delta was made to work with OData (and the formatter), but without something like Delta using PATCH without Delta become a difficult thing to implement, when you are allowing partial updates of a resource and do not restrict the fields that can be passed.</p> <p>Is there an alternative out there?</p> <p><strong>Related Question - have the same issue, int/decimal etc. don't update</strong></p> <p><a href="https://stackoverflow.com/questions/15561874/deltat-in-patch-actions-not-tracking-primitive-types">Delta&lt;T&gt; in PATCH actions not tracking primitive types</a></p> <p><strong>UPDATED TO INCLUDE SOME CODE FOR CONTEXT</strong></p> <p>The POST/PATCH/PUT Types will be simplified to specific DTOs so that i can reduce the noise of the objects but for now i am using my Model objects directly as i was just trying ot get it working.</p> <p><strong>PATCH Route</strong></p> <pre><code> public HttpResponseMessage Patch(int id, Delta&lt;Measurement&gt; measurement) { var resp = new HttpResponseMessage(HttpStatusCode.OK); var dbMeasurement = (from n in _repo.Include("SurveyItem") where n.Id == id select n).SingleOrDefault(); measurement.Patch(dbMeasurement); _uow.Commit(); var measurementRep = dbMeasurement.ToRepresentation&lt;Measurement, MeasurementRepresentation&gt;(); resp.Content = new ObjectContent&lt;MeasurementRepresentation&gt;(measurementRep, new JsonHalMediaTypeFormatter()); return resp; } </code></pre> <p><strong>FIDDLER POST OPTIONS</strong></p> <p><em>Headers</em></p> <pre><code>User-Agent: Fiddler Host: localhost:1996 Content-Length: 25 Content-Type: application/json </code></pre> <p><em>Body</em></p> <pre><code>{ "Value":101.00 } </code></pre> <p>a 200 is returned but nothing is updated.but what is more telling is the following, value is 0:</p> <p><img src="https://i.stack.imgur.com/Twx9k.png" alt="Delta"></p> <p>I can persist strings, just no other types.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload