entity-framework - EF Core Second level ThenInclude misworks

标签 entity-framework include .net-core entity-framework-core

假设首先拥有这些模型:
Method有一个 OriginalCodeOriginalCode有很多MutantMutant有很多ParseSubTree

现在在 Method 上查询时我想要另一个被加载。所以我有以下几点:

Method targetMethod = dBContext.Methods
            .Include(me => me.OriginalCode)
                .ThenInclude(oc => oc.Mutants)
            .FirstOrDefault(me => me.Id == id);

下一步是额外包含 ParseSubTree .但问题是我无法访问它。见下图:

mu is a list except object reference

问题是“mu 是一个列表而不是一个对象引用”!

我的错在哪里!

TG。

最佳答案

这是 ThenInclude 的已知 Intellisense 问题集合类型导航属性的重载,由 Completion missing members of lambda parameter in fault tolerance case #8237 跟踪Roslyn GitHub 问题。

在它得到修复之前,只需键入属性的名称,它就会成功编译并按预期工作。

.ThenInclude(mu => mu.ParseSubTrees) 

更新:现在它甚至在 Including multiple levels 中特别提到EF Core 文档的部分:

Note

Current versions of Visual Studio offer incorrect code completion options and can cause correct expressions to be flagged with syntax errors when using the ThenInclude method after a collection navigation property. This is a symptom of an IntelliSense bug tracked at https://github.com/dotnet/roslyn/issues/8237. It is safe to ignore these spurious syntax errors as long as the code is correct and can be compiled successfully.

关于entity-framework - EF Core Second level ThenInclude misworks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45658411/

相关文章:

sql-server - SQL Server 分区表和 Entity Framework

entity-framework - 如何使用 EF 将数据从一张表 "transfer"到另一张表?

php - 包含php文件

c - 包含二进制文件作为常量数组

.Net Core DebugDiag 等价物

c# - Entity Framework 使编译查询通用

c# - Entity Framework Core - 迁移 - 没有为此对象定义无参数构造函数

c++ - Visual Studio 2015 默认附加库

c# - .Net Core 2.1.2 版本设置和 Controller 脚手架(序列不包含任何元素)

使用 Novell.Directory.Ldap.NETStandard 库的 C# netcore ldap 身份验证