0

I am using below with two DbContexts:

https://github.com/SimonCropp/GraphQL.EntityFramework

I get this error:

GraphQL.ExecutionError: Error trying to resolve project.

System.Collections.Generic.KeyNotFoundException: The given key 'Models.Master.Project' was not present in the dictionary.

at System.Collections.Generic.Dictionary2.get_Item(TKey key)
at IncludeAppender.AddIncludes[TItem,TSource](IQueryable
1 query, ResolveFieldContext1 context) in C:\\projects\\graphql-entityframework\\src\\GraphQL.EntityFramework\\IncludeAppender.cs:line 20
at GraphQL.EntityFramework.EfGraphQLService.<>c__DisplayClass21_0
2.<b__0>d.MoveNext() in C:\projects\graphql-entityframework\src\GraphQL.EntityFramework\EfGraphQLService_Queryable.cs:line 80

End of stack trace from previous location where exception was thrown

at GraphQL.Instrumentation.MiddlewareResolver.Resolve(ResolveFieldContext context)
at GraphQL.Execution.ExecutionStrategy.ExecuteNodeAsync(ExecutionContext context, ExecutionNode node)

End of inner exception stack trace

When I try to add two models of two DbContexts as following in startup.cs (in following, if I remove second line, then it works perfectly. But that I need for my second DbContext).

EfGraphQLConventions.RegisterInContainer(services, ProjectDataContextBuilder.ProjectModel); //This is creating issue as of now. wasn't issue when checked with my and your.
EfGraphQLConventions.RegisterInContainer(services, MasterDataContextBuilder.MasterModel);

DataContextBuilder classes are as follows:

static class MasterDataContextBuilder
{
    static MasterDataContextBuilder()
    {
        using (var masterDataContext = InMemoryContextBuilder.Build<ecdiscoMasterContext>())
        {
            MasterModel = masterDataContext.Model;
        }
    }

    public static IModel MasterModel;
}

static class ProjectDataContextBuilder
{
    static ProjectDataContextBuilder()
    {
        using (var projectDataContext = InMemoryContextBuilder.Build<ecdiscoProjectContext>())
        {
            ProjectModel = projectDataContext.Model;
        }
    }

    public static IModel ProjectModel;
}

Note: In error. Project is model of MasterDbContext.

Another DbContext is Project. which is separate per tenant. So that is ProjectDbContext (which doesn't have Project model).

1 Answer 1

1

this is fixed in version 6 https://github.com/SimonCropp/GraphQL.EntityFramework/blob/master/doco/configuration.md#multiple-dbcontexts

Some extra text to get over the silly 30 char min

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.