Skip to content

Multiple EF contexts #269

Closed
Closed
@joshhubers

Description

@joshhubers

First off, thanks for the fantastic library. It has been extremely beneficial for my project.

Is it possible to use multiple EF Core DbContexts? I'm attempting to add two different contexts, but the second overrides the first.

Ex.

services.AddJsonApi<ContextA>(opt =>
        {
            opt.AllowCustomQueryParameters = true;
            opt.Namespace = "api/v1";
        }, mvcBuilder);

services.AddJsonApi<ContextB>(opt =>
        {
            opt.AllowCustomQueryParameters = true;
            opt.Namespace = "api/v1";
        }, mvcBuilder);

Where both ContextA and ContextB are EF Core DbContext's.

When I request resources from controllers that use ContextB, I get the resources as expected. When I request from controllers that use ContextA I get a
"ArgumentException","detail":"DbSet of type {DbSet of ContextA} not found on the DbContext"

Commenting out the first AddJsonApi call changes the which context is working as expected.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions