gpt4 book ai didi

c# - 使用带有 json 补丁的 ASP.NET Core 更新嵌套元素

转载 作者:太空宇宙 更新时间:2023-11-03 15:06:52 25 4
gpt4 key购买 nike

有人知道如何使用 asp.net core json 补丁更新项目的嵌套元素吗?

我尝试使用 xx.Operations.Add(new Operation<DataRequestModel>("Replace", $"schedules/{scheduleId}/status", null, DataRequestStatusEnum.ExtractionFailed));

但它抛出异常The path segment '43688769-f45e-4e84-a8d6-f071c077b9ad' is invalid for an array index.当我使用 model.ApplyTo(dataRequest);在补丁操作中。

感谢您的帮助。

最佳答案

我是用

Controller

    [Route("{some}/adress")]
[HttpPatch]
public bool YourDtoUpdate(long some, [FromBody]JsonPatchDocument<TestpDTO> testChanges)
{
var tsd = new TestDTO(){Nested = new NestedClass()};
testChanges.ApplyTo(tsd);
}

服务

    var model = new TestDTO() { Foo = "abc", Nested = new NestedClass()};
JsonPatchDocument<TesDTO> patchDoc = new JsonPatchDocument<TestDTO>();
patchDoc.Replace(e => e.Foo , model.Foo );
patchDoc.Replace(e => e.Nested.Bar, model.Nested.Bar);

关于c# - 使用带有 json 补丁的 ASP.NET Core 更新嵌套元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43055702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com