Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

entity framework - EF Core Second level ThenInclude missworks

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:

mu is a list except object reference

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

Where is my mistake!

TG.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...