'Entity Framework .Include() Navigation of another Navigation property

I have an entity Test. It contains a Navaigation Property Question and Question contains a Navigation Property QuestionLocale.

var test = context.Tests
       .Include("Question")
       .FirstOrDefault();

works as expected. But how is it possible to include the QuestionLocale?



Solution 1:[1]

You can do it in a strongly typed way too

var test = context.Tests
                .Include(x => x.Question.Select(child => child.QuestionLocale))
                .FirstOrDefault()

Solution 2:[2]

Now there is ThenInclude see Microsoft Documentation, that solved it for me

var test = context.Tests.Include(x => x.Question).ThenInclude(q => q.QuestionLocale).FirstOrDefault();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Juan Salvador Portugal
Solution 2 N3Q