EF Core 二级 ThenInclude 失误

编程入门 行业动态 更新时间:2024-10-12 18:19:08
本文介绍了EF Core 二级 ThenInclude 失误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Assume having these models first:

Method that has one OriginalCode OriginalCode that has many Mutants Mutant that has many ParseSubTrees

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);

and the next step is to include additionally the ParseSubTree. But the thing is that I can't access it. See the following Image:

the problem is "mu is a list instead of being an object reference"!

Where is my mistake!

TG.

解决方案

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)

Update: Now it's even specifically mentioned in the Including multiple levels section of the EF Core documentation:

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 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 二级 ThenInclude 失误

本文发布于:2023-11-13 22:55:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585546.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:EF   Core   ThenInclude

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!