Error PATCH'ing with json relationship
See original GitHub issueI’ll do my best to be brief and descriptive.
I should mention the application has two DbContexts and so far everything has been working well.
I have two seperate IDbContextResolvers, one for each of my database contexts. I DI the resolvers, and have seperate base repositories for each database connection and repositories for each model that extend from the two repositories. (As per #269 ).
I have a model EntityA which has a has-one relationship with EntityB
public class EntityA : Identifiable<int>
[InverseProperty("EntityAs")]
public virtual EntityB EntityB { get; set; }
EntityB has-many EntityA’s
public class EntityB : Identifiable<int>
[InverseProperty("EntityB")]
[HasMany("EntityAs")]
public ICollection<EntityA> EntityAs { get; set; }
Calling a PATCH to EntityB endpoint works as expected when I DO NOT include the json relationships: ...
which include EntityA’s
Calling a PATCH to EntityB endpoint errors when PATCH’ing with relationships included…
fail: JsonApiDotNetCore.Formatters.JsonApiReader[0]
An error occurred while de-serializing the payload JsonApiDotNetCore.Internal.JsonApiException: Failed to deserialize request body ---> System.InvalidOperationException: Unable to resolve service for type 'JsonApiDotNetCore.Data.
IDbContextResolver' while attempting to activate 'JsonApiDotNetCore.Internal.Generics.GenericProcessor`1[EntityA]'.
Endpoints for both EntityA and EntityB work fine, with no issues or other errors. Both EntityA and EntityB belong to the same repository and should fall under the same context resolver. I don’t believe I’m missing anything obvious as everything else has been working perfectly, and I’m not sure if it’s an issue because of the multiple IDbContextResolvers or not.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
@jaredcnance Looks to be working on my end!
@joshhubers this should be fixed by #254.
There is some mixing of concerns in the de-serialization process that required this call:
https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/c2e6779abc0f08fb3666b36ea63944cde8092de6/src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs#L241
The original approach to updating relationships, was to actually fetch the relationship so EF would track it and it could be updated 😞 . However, #254 is removing that requirement. The reason you are getting the above error is because when we try to resolve the
GenericProcessor<EntityA>
, it is failing to resolveIDbContextResolver
:https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/c2e6779abc0f08fb3666b36ea63944cde8092de6/src/JsonApiDotNetCore/Internal/Generics/GenericProcessor.cs#L25
So, while the error you’re currently experiencing will be fixed soon, I think there may still be some other lurking issues, especially when trying to use the new implementation of json:api v1.1 operations.