How do i patch enumerables with Odata.Delta with Webapi

烂漫一生 提交于 2019-12-11 15:03:32

问题


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.



来源:https://stackoverflow.com/questions/14506353/how-do-i-patch-enumerables-with-odata-delta-with-webapi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!