dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.4k stars 10k forks source link

Apply JsonPatch when set of properties are different in DTO than Entity #2422

Closed aspnet-hello closed 6 years ago

aspnet-hello commented 6 years ago

From @sachinpachori on Wednesday, December 27, 2017 3:19:02 PM

This is a common scenario where your DTO/viewmodel could be different from the Entities. In this case how to use this JSONPatch with ApplyTo function. If possible, I think you should work on providing this feature.

Copied from original issue: aspnet/JsonPatch#127

mkArtakMSFT commented 6 years ago

This is not a functionality we provide explicitly, but you can use something like AutoMapper(http://automapper.org/) to handle it.

RoboBurned commented 5 years ago

It is almost useless without this feature. void Patch(JsonPatchDocument patch) { patch.ApplyTo(userEntity); } I cannot use it this way because my UserEntity has collection of Roles and anybody can "patch" it. We need to separate the list of fields in patch from the entity.

migpfernandes commented 5 years ago

Hi, is there any new solution to perform this kind of actions? I've two scenarios for this where I'm getting stuck: 1) I have a gateway that first receives the PatchDocument and then propagates request for proper service through it's SDK. Gateway type is JsonPatchDocument and service is JsonPatchDocument. Any elegant way of converting one to another? 2) In service we want to receive the JsonPatchDocument but apply it to Service.Domain.Contact. Is this possible without getting domain object, mapping to DTO, applying Patch and converting to Domain object again?