Another alternative to published options:
var cityList = network.Continents .SelectMany(continent => continent.Countries) .Where(ctry => ctry.Id == "country") .SelectMany(ctry => ctry.Cities, c => new City { Id = c.Id, Name = c.Name }) .ToList();
This overload of SelectMany (in the second call) is the one used by the C # compiler in query expressions. Please note: if you want to write it as a query expression, you can do it easily:
var cityList = (from continent in network.Continents from country in continent.Countries where country.Id == "country" from city in country.Cities select new City { Id = city.Id, Name = city.Name }).ToList();
In LINQ to Objects, the query expression will be slightly less efficient than the dotted notation form in this particular case, because the continent and country variables will propagate to the select clause ... but I would expect that the SQL generated by any LINQ database provider should be the same thing, and even inside LINQ to Objects, the difference is likely to be negligible.
Note that you do not need to specify a type argument when calling ToList - the type will be inferred as City already.
source share