【问题标题】:KeyNotFoundException in GraphQL .net Entity FrameworkGraphQL .net 实体框架中的 KeyNotFoundException
【发布时间】:2019-06-02 17:07:31
【问题描述】:

我在下面使用两个DbContexts:

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

我收到此错误:

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

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

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

堆栈跟踪从上一个异常位置结束 被扔了

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

内部异常堆栈跟踪结束

当我尝试在startup.cs 中添加两个DbContexts 的两个模型时(接下来,如果我删除第二行,那么它可以完美运行。但是我需要第二个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的模型。

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

【问题讨论】:

    标签: c# entity-framework graphql


    【解决方案1】:

    这在版本 6 中已修复 https://github.com/SimonCropp/GraphQL.EntityFramework/blob/master/doco/configuration.md#multiple-dbcontexts

    一些额外的文字来克服愚蠢的 30 char min

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-24
      • 2014-07-21
      • 1970-01-01
      • 2013-04-17
      • 1970-01-01
      • 1970-01-01
      • 2012-05-07
      相关资源
      最近更新 更多