Skip to content

Diagnostics analyzer for unnecessary Include #28449

@enricobenedos

Description

@enricobenedos

Good morning,

after upgrading Entity Framework Core to .NET 6 I faced a breaking change on my production API that was not listed on these docs.

It is related to Microsoft.EntityFrameworkCore.Query.NavigationBaseIncludeIgnored that change the EF Core behaviour when using multiple level properties.
The solution is explained on this question on Stack Overflow.

Old working code:

Tour tour = await _context.Tours.Include(mpt => mpt.MarkersPerTours)
                                                 .ThenInclude(mrk => mrk.Marker)
                                                 .ThenInclude(mrkProp => mrkProp.MarkersTranslations)
                                                 .ThenInclude(mrk => mrk.Marker)
                                                 .ThenInclude(mrkTp => mrkTp.Type)
                                                 .FirstOrDefaultAsync(t => t.Id == tourId);

New working code:

Tour tour = await _context.Tours.Include(t => t.MarkersPerTours)
                                                    .ThenInclude(mpt => mpt.Marker)
                                                    .ThenInclude(mrk => mrk.MarkersTranslations)
                                                 .Include(tour => tour.MarkersPerTours)
                                                    .ThenInclude(mpt => mpt.Marker)
                                                    .ThenInclude(mrk => mrk.Type)
                                                 .FirstOrDefaultAsync(t => t.Id == tourId);

Can it be a good idea to include it in the docs?

Thank you

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions