Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Core Second level ThenInclude missworks

Tags:

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.

like image 726
ConductedClever Avatar asked Aug 13 '17 08:08

ConductedClever


People also ask

Should I use async with EF core?

The rule of thumb is to use async on any thread that by it's busy type waiting, would hamper other threads. For the use of async will have the operations of waiting to step it aside until the data return.

Can Core 3.1 Use EF Core 5?

EF Core 5.0 requires a . NET Standard 2.1 platform. This means EF Core 5.0 will run on . NET Core 3.1 or .

Is EF core production ready?

The attention being paid to EF Core in this version demonstrates that there's no question about EF Core being production ready.


1 Answers

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.

like image 117
Ivan Stoev Avatar answered Sep 25 '22 03:09

Ivan Stoev