Fetching in query causes incorrect/missing joins in subquery

Description

Given this Data Model, where there are 3 joins between Tag and DisciplineType :

When I execute this Linq query:

I expect the generated SQL to be this:

However, this is the actual SQL generated:

This results in the Where clause in the subquery to try and filter the subresults using a table in the outer query.

This always happens whenever I need to use ThenFetch to eager load something that requires two or more joins.

This is causing the query to execute extremely slowly.

Environment

MS SQL Server 2012

Assignee

Unassigned

Reporter

Anish Patel

Labels

Components

Affects versions

Priority

Major
Configure