JolPatchDocument Access ICollection

I am trying to replace an object in a list using JsonPatchDocument, but I get an exception when I try to access a collection member with the correct path, here is my code:

    var oppfour = new Operation<Application>("replace", "/comments/0", "", obj);

    var contractResolver = new DefaultContractResolver();
    var operations = new List<Operation<Application>>();

    operations.Add(operation);
    operations.Add(opptwo);
    operations.Add(oppthree);
    operations.Add(oppfour);

    var patchJson = new JsonPatchDocument<Application>(operations, contractResolver);

    try
    {
        patchJson.ApplyTo(app);
    }

      

the data model I'm trying to access looks like this:

public class Application: BaseEntity
{
    public virtual ICollection<Comment> Comments { get; set; }
}

      

Here's an exception:

Microsoft.AspNetCore.JsonPatch.Exceptions.JsonPatchException: The target location specified by path segment '0' was not found.

How can I set the path to replace something at a specific point in the collection?

+3
c # entity-framework patch


source to share


No one has answered this question yet

See similar questions:

fourteen
Web API 2 - Implementing PATCH

or similar:

683
Error - Unable to access the IIS metabase
529
Invalid cross-stream operation: control is from a thread other than the one that was created on
328
Why use ICollection over IEnumerable or List <T> for many-many / one-many relationships?
2
Cannot read value item parameter from data reader in combobox
2
SSIS getting exception while accessing Int variable
2
ICollection on an interface with a different interface as a type
1
Accessing SQL Server File Table from IIS APP POOL
1
Unauthorized access to folders when creating xml file
0
C # Errors when doing simple datarow comparison
0
General collection T for ICollection of DbEntities



All Articles
Loading...
X
Show
Funny
Dev
Pics