假设首先拥有这些模型:Method
有一个 OriginalCode
OriginalCode
有很多Mutant
秒Mutant
有很多ParseSubTree
秒
现在在 Method
上查询时我想要另一个被加载。所以我有以下几点:
Method targetMethod = dBContext.Methods
.Include(me => me.OriginalCode)
.ThenInclude(oc => oc.Mutants)
.FirstOrDefault(me => me.Id == id);
下一步是额外包含
ParseSubTree
.但问题是我无法访问它。见下图:问题是“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/