How do i patch enumerables with Odata.Delta with W

2019-08-28 11:15发布

问题:

I´m trying to use System.Web.Http.OData.Delta to implement PATCH methods in ASP.NET Web API services, but it seems unable to apply changes to properties of type IEnumerable.

This is my code:

public class Person
{
        [Required]
        public string Name { get; set; }

        public IList<Document> AdditionalDocuments { get; set; }

        public HomeAddress HomeAddress { get; set; }
}


public class HomeAddress
{
    public string StreetName { get; set; }
}

public class Document
{
    public string Value { get; set; }
}

The patch is implemented like this:

[AcceptVerbs("PATCH")]
public void Patch(string id, Delta<Person> delta)
{
    var person = personRepository.GetById(id)
    delta.Patch(person);
}

My problem is that when i patch the informations, the HomeAddress and the AdditionalDocuments are being ignored. I found another article(How do I patch enumerables with System.Web.Http.OData.Delta?) here, but i couldn´t implement the solution because i didn´t know how to internalize the Delta code. May someone help me?

回答1:

Delta was designed to work with only the OData formatter. There is a bug open to make it work with json.net formatter.