Include / ThenInclude in EF Core

.net-core c# entity-framework-core

Question

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?

1
1
3/15/2018 10:15:38 AM

Popular Answer

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)
3
3/15/2018 11:36:19 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow