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.Dictionary
2.get_Item(TKey key)1 query, ResolveFieldContext
at IncludeAppender.AddIncludes[TItem,TSource](IQueryable1 context) in C:\\projects\\graphql-entityframework\\src\\GraphQL.EntityFramework\\IncludeAppender.cs:line 202.<b__0>d.MoveNext() in C:\projects\graphql-entityframework\src\GraphQL.EntityFramework\EfGraphQLService_Queryable.cs:line 80
at GraphQL.EntityFramework.EfGraphQLService.<>c__DisplayClass21_0End 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).