Delta in PATCH actions not tracking primitive t

2020-02-26 12:47发布

问题:

I'm using Delta for patching an entity as outlined in "Partial Updates(PATCH request)" section outlined here I have the following ProductDTO:

 public class ProductDTO
{
    public int ID { get; set; }
    [Required]
    public string Name { get; set; }
    [UIHint("Date")]
    [DataType(DataType.Date)]
    public DateTime? ModifiedOn { get; set; }
    public int Price { get; set; }
}

And the following action method defined:

    public HttpResponseMessage Patch(int id, Delta<ProductDTO> delta)
    {
        return Request.CreateResponse(HttpStatusCode.NoContent);
    }

If I pass in the following JSON (via Fiddler using the PATCH verb)

{"ID":1,"Name":"test","Price":"1000"}

The "delta" in the action method contains only the "Name" property and not the ID and Price properties. It appears that the delta is not containing values of types "int","decimal" and primitive types in general.

What am I missing here?

TIA

EDIT: Here is a link to a modded version of Delta that includes support for primitive JSON data types. Comments appreciated