Skip to content

Error PATCH'ing with json relationship #282

Closed
@joshhubers

Description

@joshhubers

I'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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions