Error: Unable to Navigate
So Entity Framework Core doesn't support lazy loading of navigational properties. This isn't the worst thing in the world, but it does become a bit of a problem when given this fact:
If you change the query so that it no longer returns instances of the entity type that the query began with, then the include operators are ignored.
From the MS docs:
In the following example, the include operators are based on the Blog, but then the Select operator is used to change the query to return an anonymous type. In this case, the include operators have no effect.
using (var context = new BloggingContext()) { var blogs = context.Blogs .Include(blog => blog.Posts) .Select(blog => new { Id = blog.BlogId, Url = blog.Url }) .ToList(); }
So now, because of this, I have this monstrosity of a query:
var submissions = await _db.Submissions .Include(x => x.answers) .ThenInclude(x => x.question) .Include(x => x.answers) .ThenInclude(x => x.answer) .Include(x => x.answers) .ThenInclude(x => x.cardchoices) .ThenInclude(x => x.card) .Include(x => x.answers) .ThenInclude(x => x.choiceanswers) .ThenInclude(x => x.answer) .Where(x => x.surveyid == id) .Where(x => x.answers.Any()) .Select(x => x.answers .OrderBy(y => y.question.sortorder) .Select(y => new { question = y.question.sortorder, answer = y.answer.text, text = y.text, cards = string.Join(", ", y.cardchoices.Select(z => z.card.gameid)), selections = y.choiceanswers.Select(z => z.answer) }) ) .ToListAsync();
This is what I get for writing a form builder. I'm still not even sure how to transform the data so it shows up nicely in a table. I think I'm going to have to write some manual joins, which means messing with my model to add in explicit ids/foreign keys. Not gonna lie, I miss EF6 a bit.














