0 votes
by (2.0k points)

I have boiled down my error to the following. If I have simple models like so : 

class Person
{
	public int Id { get; set; }
	public ICollection<Class> Classes { get; set; }
	public ICollection<Address> Addresses { get; set; }
}

class Class 
{
}

class Address
{
}

And then I write EF code that does multiple includes : 

_context.Persons
	.Include(x => x.Classes)
	.ThenInclude(x => x.Person)
	.ThenInclude(x => x.Addresses);

I get this error when I didn't get it on .NET 5 : 

"System.InvalidOperationException: An error was generated for warning 'Microsoft.EntityFrameworkCore.Query.NavigationBaseIncludeIgnored': The navigation '' was ignored from 'Include' in the query since the fix-up will automatically populate it. If any further navigations are specified in 'Include' afterwards then they will be ignored. Walking back include tree is not allowed. This exception can be suppressed or logged by passing event ID 'CoreEventId.NavigationBaseIncludeIgnored' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'."

1 Answer

0 votes
by (2.0k points)

It seems like this is an undocumented change, with the most I could find here : https://github.com/dotnet/EntityFramework.Docs/issues/3653

It basically boils down to the fact that EF Core 6 doesn't allow you to backtrack through entities using "ThenIncludes". If you need to go back to the start where you came from, you can use Include again to start at the initial type. 

So in the above example, it would look like so : 

_context.Persons
	.Include(x => x.Classes)
	.Include(x => x.Addresses);

While this example is kinda trivial and maybe the backtracking here isn't that logical, it would make sense if we were going multiple levels deep and having to restart at the initial "Persons" wouldn't make too much sense. 

In anycase, you can't use ThenInclude to traverse back from where you came from it seems. 

Welcome to .NET Q&A, where you can ask questions and receive answers from other members of the community.
...