This project is read-only.

Enum support for Delta<T> Patch

Topics: ASP.NET Web API
Jan 16, 2013 at 4:54 PM
Edited Jan 16, 2013 at 4:57 PM

I know there is a known issue where Delta<T> does not support complex types at all and this was supposed to be fixed in the latest nightly builds... However, I'm been trying to do a patch for a very basic enum property on a class..

public enum Mode {
    Normal = 0,
    Running= 1
public Mode Mode { get; set; }

When I post the following json:


 nothing happens. The Delta<T>'s Changed Properties collection never contains this value.. I've tried everything, including the latest nightly builds from NuGet.

Jan 16, 2013 at 7:10 PM

Enum's are not standard odata types. we in webapi odata map enums as strings in the edm model. So, the json that you are sending is incorrect. you should be sending 

{ 'Mode' : 'Running' }

Jan 16, 2013 at 8:13 PM

Thanks for that information. I tried that before in both the latest nightly build and stable. No mater what I try I can't get it to work with my ajax call.


$.ajax('/api/v1/test/1', {
    type: 'PATCH',
    dataType: 'json',
    contentType: 'application/json;charset=utf-8',
    data: JSON.stringify({ Mode: 'Running' })


Every time, my delta doesn't contain any changed values. I can send/attach a sample app if you would like that reproduces this with any version of the webapi odata libs.

Also, one would think you would post an number value as it's serialized over webapi as an int and not a string. Which would make it difficult to pull down an entity, make one change and patch it back to the server using a delta.

Jan 16, 2013 at 9:17 PM

sure. please do share a repro. that would be super helpful.

Jan 16, 2013 at 9:44 PM


Here is a link to the sample (included everything but bin/obj/packages folder): I created a new webapi project, updated nuget packages, modified api controller and main index home view. Just open the js console to see extra messages on the home view.

Please let me know if you have any questions.

Jan 17, 2013 at 4:52 PM


Were you able to reproduce with the sample above?

Jan 17, 2013 at 6:58 PM

Hey blake05,

I was able to repro your issue successfully. Unfortunately, Delta<T> was tested with only the ODataFormatter. We never tried Delta<T> with the json formatter. Some of the things might be working with the inbuilt json formatter as Delta<T> is also a DynamicObject.

Have you considered using the ODataMediaTypeFormatter ? I know there is more work in exposing an OData service and opting into the odata format. 

Jan 17, 2013 at 7:23 PM


Thanks for the heads up, I didn't really see this anywhere in the initial documentation, but found it after a lot of clicking. They say there is a ton of issues with using ODataMediaTypeFormatter with JSON.NET. I guess I'll have to look into this...

Considering is being used everywhere and also has insane momentum... It seems like this should be supported out of the box... Especially since web api actions only return xml/json...


Jan 17, 2013 at 7:25 PM

Please open an issue on codeplex and we will try to fix it :)

Jan 17, 2013 at 7:46 PM

Thanks, I added the issue here. Please let me know if I need to update the description :).

Jan 17, 2013 at 7:50 PM

odata already supports json. so Delta<T> has support for json. I updated the title to say to minimize confusion.

Dec 17, 2013 at 6:28 PM
I've uploaded a sample showing how to configure Json.NET to deserialize Delta<T>. Please let us know if this works for you.

In the future we'd like to build a bespoke feature that fills this gap and doesn't have the limitations of Delta<T>, but it's not going to make it for this release.
Dec 18, 2013 at 4:32 AM
Hey look at that :-) A solution the day after I created my own

DeltaHack<TEntityType> : Delta<TEntityType> where TEntityType : class

to force my own conversions and get it working..

The DeltaContractResolver looks to work nicely in my scenario....
I was having trouble with Ints and Dates saturating the Delta's from an AJAX PATCH call but now I can remove my hack and use this..

Thanks for this :-)