本文介绍了如何使用Webapi使用Odata.Delta修补可枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用System.Web.Http.OData.Delta在ASP.NET Web API服务中实现PATCH方法,但是似乎无法将更改应用于IEnumerable类型的属性.

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.

这是我的代码:

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);
}

我的问题是,当我修补信息时,将忽略HomeAddress和AdditionalDocuments.我发现了另一篇文章(如何修补枚举使用System.Web.Http.OData.Delta?),但是我无法实现该解决方案,因为我不知道如何内部化Delta代码.有人可以帮我吗?

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?

推荐答案

Delta设计为仅与OData格式化程序一起使用.有一个 bug 可以与json.net格式化程序一起使用.

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

这篇关于如何使用Webapi使用Odata.Delta修补可枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 15:53