Reputation: 27927
Let's say I have DB Tables like that:
Continent -> Countries -> Cities
-> Lakes
Now i want to include them
_db.Continents
.Include(p => p.Countries)
.ThenInclude(c => c.Cities)
.Include(p => p.Countries)
.ThenInclude(p => p.Lakes)
Is this the only way (by including countries twice) or is there another way?
Upvotes: 1
Views: 730
Reputation: 821
There is actually support for this as of EF Core 2.1. The pattern looks something like this:
_db.Continents.Include(p => p.Countries).ThenInclude(c => c.Cities).ThenInclude((Country p) => p.Lakes)
Upvotes: 3
Reputation: 3660
As said before EF Include countries only once.
for better reading you can write it like that :
_db.Continents
.Include(p => p.Countries.Select(s => s.Cities))
.ThenInclude(p => p.Countries.Select(s => s.Lakes))
Upvotes: -2