我需要您有关OData的帮助,尤其是有关Delta请求的帮助。
在我的ODataController控制器扩展中:
[HttpPatch("{key}/edit")]
[AcceptVerbs("PATCH", "MERGE")]
public IActionResult PostEdit(Guid key, Delta<Bike> request)
{
Bike p = _bikeRespository.Get(key);
if (request == null)
throw new NullReferenceException("unable to find id");
request.Patch(p);
_bikeRespository.SaveChangesAsync();
return Ok(p);
}
所以我和邮递员一起做请求
url:http://localhost:5001/api/Bike/f6e4d714-debc-4df8-827d-0c80f50944ee/edit
请求正文:
{"Name": "YZR M1123",
"productid":"58d6c929-258c-44d9-b0e7-40907e638190",
"Price": 21000,
"IsSecond" : true }
响应正文:
{"id": "f6e4d714-debc-4df8-827d-0c80f50944ee",
"name": "YZR M1123",
"productId": "e541382f-6143-41ba-b954-1a2b2f5791f6",
"price": 50000000,
"isSecond": true,
"dateRelease": "0001-01-01T00:00:00"}
IsSecond
和名称值已更改,但productId
和价格未更改
像这样的自行车课
public class Bike : IEntity<Guid>
{
public Guid Id { get; set; } = Guid.NewGuid();
public string Name { set; get; }
public Guid productId { set; get; }
public int Price { set; get; }
public bool IsSecond { set; get; }
public DateTime DateRelease { set; get; }
[JsonIgnore]
[ForeignKey(nameof(productId))]
public Product Product { set; get; }
}
有什么问题或缺少吗?