假设首先拥有这些模型:
Assume having these models first:
Method 有一个 OriginalCodeOriginalCode 有很多 MutantMutant 有很多 ParseSubTrees
Method that has one OriginalCode OriginalCode that has many Mutants Mutant that has many ParseSubTrees
现在在查询 Method 时,我希望加载另一个.所以我有以下几点:
Now when querying on Method I want the other being loaded. So I have the following:
Method targetMethod = dBContext.Methods .Include(me => me.OriginalCode) .ThenInclude(oc => oc.Mutants) .FirstOrDefault(me => me.Id == id);下一步是额外包含ParseSubTree.但问题是我无法访问它.见下图:
and the next step is to include additionally the ParseSubTree. But the thing is that I can't access it. See the following Image:
问题是mu 是一个列表,而不是一个对象引用"!
the problem is "mu is a list instead of being an object reference"!
我的错在哪里!
TG.
推荐答案这是集合类型导航属性的 ThenInclude 重载的一个已知 Intellisense 问题,由 在容错案例 #8237 中补全 lambda 参数的缺失成员 Roslyn GitHub 问题.
This is a known Intellisense issue with the ThenInclude overload for collection type navigation properties, tracked by the Completion missing members of lambda parameter in fault tolerance case #8237 Roslyn GitHub issue.
在修复之前,只需键入属性的名称,它就会成功编译并按预期工作.
Until it gets fixed, simply type the name of the property and it will compile successfully and work as expected.
.ThenInclude(mu => mu.ParseSubTrees)更新:现在它甚至在 包括多级EF Core 文档的 部分:
Update: Now it's even specifically mentioned in the Including multiple levels section of the EF Core documentation:
注意
当前版本的 Visual Studio 提供不正确的代码完成选项,并且在集合导航属性之后使用 ThenInclude 方法时,可能会导致正确的表达式被标记为语法错误.这是在 github/dotnet/roslyn/issues 跟踪的 IntelliSense 错误的症状/8237.只要代码正确并且可以成功编译,就可以安全地忽略这些虚假的语法错误.
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 github/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.
更多推荐
EF Core Second level ThenInclude misworks
发布评论