aspnet / JsonPatch

[Archived] JSON PATCH library. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
103 stars 48 forks source link

ICollection<T> not supported for collection operations #76

Closed andulv closed 7 years ago

andulv commented 7 years ago

It seems like only IList<> is supported.

And since Entity Framework Core uses HashSet (which implements ICollection<> but not IList<>) this prevents us from using JsonPatch to update EF Core Entities with subcollections (navigation properties).

rynowak commented 7 years ago

@andulv - can you provide an example of what the model object would look like in this case?

In general the collection-based functionality that JsonPatch has is based on indexing with numerical indices, which implies that collections have ordering semantics. This is a real mismatch with HashSet<> and ICollection<> which is why we did IList<>

andulv commented 7 years ago

It seems like we can fix this by switching to IList<> in our models.

For some reason I thought Entity Framwork required ICollection for navigation collections, but it seems like I was wrong (or outdated).

We are currently evaluating Json Patch for a new Web Api we are doing in .NET Core. Our underlying data model is Entity Framework Core and we hope to expose this model directly.

Refering to entries in subcollections by index and not key might be a showstopper for us, but as far as I understand that is a limitation of the specifation not the implementation.