34

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?

Wahid Bitar
  • 13,776
  • 13
  • 78
  • 106
chbu
  • 985
  • 1
  • 8
  • 18

3 Answers3

66

You can use:


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

Klinger
  • 4,900
  • 1
  • 30
  • 35
4

You can do it in a strongly typed way too

var test = context.Tests
                .Include(x => x.Question.Select(child => child.QuestionLocale))
                .FirstOrDefault()
Juan Salvador Portugal
  • 1,233
  • 4
  • 20
  • 38
4

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();
N3Q
  • 41
  • 2