GraphQL .net实体框架中的KeyNotFoundException

时间:2019-04-06 18:32:45

标签: c# entity-framework graphql

我在下面使用两个DbContext

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

我收到此错误:

  

GraphQL.ExecutionError:尝试解析项目时出错。

     

System.Collections.Generic.KeyNotFoundException:字典中不存在给定的键“ Models.Master.Project”。

     在System.Collections.Generic.Dictionary 2.get_Item(TKey key)
at IncludeAppender.AddIncludes[TItem,TSource](IQueryable
1查询中的

,ResolveFieldContext 1 context) in C:\\projects\\graphql-entityframework\\src\\GraphQL.EntityFramework\\IncludeAppender.cs:line 20
at GraphQL.EntityFramework.EfGraphQLService.<>c__DisplayClass21_0
2。C:\ projects \ graphql-entityframework \ src \ GraphQL.EntityFramework中的 d.MoveNext() \ EfGraphQLService_Queryable.cs:第80行

     

从上一个异常发生的位置开始的堆栈结束跟踪   被扔了

     

在GraphQL.Instrumentation.MiddlewareResolver.Resolve(ResolveFieldContext context)
  在GraphQL.Execution.ExecutionStrategy.ExecuteNodeAsync(ExecutionContext上下文,ExecutionNode节点)

     

内部异常堆栈跟踪的结尾

当我尝试在DbContext中添加两个两个startup.cs的模型时(下面,如果我删除第二行,则可以正常工作。但是我需要第二个{{ 1}})。

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

注意:错误。项目是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; } 的模型。

另一个MasterDbContext是Project。每个租户是分开的。这样就是DbContext(没有ProjectDbContext模型)。

1 个答案:

答案 0 :(得分:1)

此问题已在版本6 https://github.com/SimonCropp/GraphQL.EntityFramework/blob/master/doco/configuration.md#multiple-dbcontexts

中修复

一些多余的文字可以克服愚蠢的30个字符分钟以上