I\'m trying to make a stackoverflow clone in my own time to learn EF6 and MVC5, i\'m currently using OWin for authentication.
Everything works fine when i have like
As you already know, Include method generate monstrous SQL.
Disclaimer: I'm the owner of the project Entity Framework Plus (EF+)
The EF+ Query IncludeOptimized method allows optimizing the SQL generated exactly like EF Core does.
Instead of generating a monstrous SQL, multiple SQL are generated (one for each include). This feature also as a bonus, it allows filtering related entities.
Docs: EF+ Query IncludeOptimized
var query = ctx.Questions
.AsNoTracking()
.IncludeOptimized(x => x.Attachments)
.IncludeOptimized(x => x.Location)
.IncludeOptimized(x => x.CreatedBy) //IdentityUser
.IncludeOptimized(x => x.Tags)
.IncludeOptimized(x => x.Upvotes)
.IncludeOptimized(x => x.Upvotes.Select(y => y.CreatedBy))
.IncludeOptimized(x => x.Downvotes)
.IncludeOptimized(x => x.Downvotes.Select(y => y.CreatedBy))
.AsQueryable();