Include() ignored when using GroupBy entity type
There is a bug in the new feature "GroupBy entity type" in EFC Core 7.
This query
var q= ctx.Flight.Include(x => x.Pilot_Person).ThenInclude(x => x.Person).ThenInclude(x => x.Person)
.Where(f => f.Pilot_Person != null)
.GroupBy(x => x.Pilot_Person)
.Select(x => new { Pilotname = x.Key.Person.Person.Surname, FlightCount = x.Count(), FreeSeatsAvg = x.Average(f => f.FreeSeats) });
var flightsGroupedByPilot = q.ToList();
foreach (var p in flightsGroupedByPilot)
{
Console.WriteLine($"Pilot {p.Pilotname}: Number of Flights: {p.FlightCount} Average Number of free Seats: {p.FreeSeatsAvg}");
}
returns always null in p.Pilotname although the names exist and I added Includes. The Includes are totally ignored in the resulting SQL. This also means, the Surname is not loaded!
SELECT [p].[PersonID], [p].[FlightHours], [p].[FlightSchool], [p].[LicenseDate], [p].[LicenseType], COUNT(*), AVG(CAST(CAST([f].[FreeSeats] AS int) AS float)) FROM [Operation].[Flight] AS [f] LEFT JOIN [People].[Pilot] AS [p] ON [f].[Pilot_PersonID] = [p].[PersonID] WHERE [p].[PersonID] IS NOT NULL GROUP BY [p].[PersonID], [p].[FlightHours], [p].[FlightSchool], [p].[LicenseDate], [p].[LicenseType]
Just for better understanding, this is the class diagramm. Surname is in table "Person".
I left the names as Scaffold-DbContext generated them 😉

Include provider and version information
EF Core version: 7.0.2 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET 7.0 Operating system: Windows
@HSchwichtenberg can you please post a minimal runnable, code sample? The above is missing your model, entity types, etc.
Note that in the above, Include should not be necessary in order to load the Pilot's Surname; the fact you're projecting it out with Select should be enough.
EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.
BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.