Entity framework generated SQL is different from 2.2 to 7

Alexander Angelo 6 Reputation points
2023-10-09T02:42:16.34+00:00
I recently upgraded a .NET core 2.1 web app to .NET 7 with upgrading EntityFrameworkCore to 7.0.1. 

a statement that use "Include" is now producing Sql queries with LEFT JOIN whereas with 2.1, they produce a mix of LEFT and INNER joins.

 _dbContext.T1
   .Include(t11 => t11.T11)
      .ThenInclude(t12 => t12.T12)
   .Include(p => p.P)
   .AsNoTracking()

produces

2.1 :

FROM T12
  INNER JOIN (
    SELECT DISTINCT ..................
    FROM T11
      INNER JOIN (
        SELECT ......
        FROM T1 
        LEFT JOIN P .........................

7 : 

FROM T1
LEFT JOIN P
 LEFT JOIN (
    SELECT ------
    FROM T11 
      LEFT JOIN T12
      -----

Wonder why the latest EFCore 7 produces a different SQL query to 2.1


I was expecting the generated SQL to be the same in both version of EFCore
Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
700 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,438 questions
{count} votes