【发布时间】:2012-11-14 16:11:50
【问题描述】:
我希望使用 Delta 包装器对 Web api 控制器操作进行部分更新。
我有一个这样的模型:
public class Person
{
public Guid PersonId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public bool IsActive { get; set; }
public int NumVacationDays { get; set; }
public double Salary { get; set; }
}
我有这样的 api 控制器:
public void Put(Delta<Person> person)
{
var p = person.GetEntity();
Person existingPerson = _repository.Get(p.PersonId);
person.Patch(existingPerson);
_repository.Update();
return;
}
我像这样调用 web api(使用 fiddler)
url: http://localhost:49933/api/Person (PUT)
Response Body
{
"PersonId": "b269c49f-8a90-41d6-b102-7cfba3812b1c",
"FirstName": "sample string 2",
"LastName": "sample string 3",
"IsActive": true,
"NumVacationDays": 5,
"Salary": 6.1
}
The controller is hit and al
l 除了 NumVacationDays(为 0)和 PersonId(默认为 00000000-0000-0000-0000-000000000000)之外,还会填充数据
有谁知道为什么 GUID 和 int 字段没有从 json 中填充?
【问题讨论】:
标签: asp.net-mvc-4 asp.net-web-api odata