2

I'm using KevinDockx-Jsonpatch library (v2.1.0 - GitHub) in a .NET Web API project to receive jsonpatch partial updates from a Web API.

I'm trying to add an element to an array with a patch like this:

[{
"op": "add",
"path": "/links/8",
"value": {
    "linkName": "test",
    "linkValue": "http://test.com",
    "id": 0,
    "websiteId": 123,
    "valid": true
}}] 

Unfortunately I'm getting this error: TargetLocationAtPathSegmentNotFound

It seems that the lib is checking not for the array position but for a path called links/4 and obviously it is not able to find it. I've also tried with links/- but there is the same problem.

My model on server is written using Entity Framework Code First approach.

So I have an object like this:

[Table("XXX.Websites")]
public partial class Website : Entity
{
    [StringLength(255)]
    public string Name { get; set; }        
    public virtual ICollection<Link> Links { get; set; }
}

Any suggestions on this?

D. Pesc.
  • 196
  • 15
  • Try removing the "/8" from the path and changing the "id" value to "8". – ParanoidCoder May 31 '18 at 16:31
  • Hello @ParanoidCoder and thanks for your reply, but it doesn't work and it's conceptually different from my intent. The "id" field it's DB id field, so setting it to 0 form Entity Framework should means "Create new record in table Likns". In my intent, with this add I'd like to: 1) create new record in table Links (I added foreign key in the post "websiteId") 2) append this relationship to my Website object. 2) add a – D. Pesc. Jun 01 '18 at 07:23

0 Answers0