gpt4 book ai didi

entity-framework - EF Core 二级 ThenInclude missworks

转载 作者:太空宇宙 更新时间:2023-11-03 14:38:27 24 4
gpt4 key购买 nike

假设首先有这些模型:

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 二级 ThenInclude missworks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59000639/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com