I was struggling with an issue that if you use data annotations for model validation in ASP.NET Core and you run patchDoc.ApplyTo(newData);
and then if (!TryValidateModel(newData))
you got model validation errors for operations not included in the patch document.
If a property was null before and it has a [Required]
attribute it will give a model state validation error although I didn't include that property in the patch document.
My starting solution is to add an extension method for
ModelStateDictionary
that looks like thisThere are issues with this method, for example when you want to change an array property this won't work as it is but it's a good start. Hopefully it helps someone! :)