Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EF7 - IsLoaded property is always false on navigation-properties when using AsNoTracking() #30140

Closed
luca-domenichini opened this issue Jan 25, 2023 · 3 comments
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported

Comments

@luca-domenichini
Copy link

Actual behaviour

Given 2 related entities Person and PersonDetail and executing a query with an Include() from Person to PersonDetail as follows, the corresponding navigation property has the IsLoaded value false

    var p = context.Persons
        .AsNoTracking()
        .Include(p => p.PersonDetail)
        .FirstAsync();

    Assert.True(context.Entry(p).Navigation(nameof(Person.PersonDetail)).IsLoaded); // this assertion fails!

Expected behaviour

The assertion should not fail, because the navigation property was loaded as part of the query.

Include provider and version information

EF Core version: 7.0.2
Database provider: Microsoft.EntityFrameworkCore.SqlServer and Microsoft.EntityFrameworkCore.InMemory
Target framework: .NET 6.0 / .NET 7.0
Operating system: Windows 10
IDE: Visual Studio 2022 17.4

Repro csproj: EF7AsNoTrackingBugTests.zip

@luca-domenichini
Copy link
Author

Ok this is by design, since when loading with - no tracking - means exactly that the DbContext do not know anything about that entity.
Closing issue.

@ajcvickers
Copy link
Member

@luca-domenichini Note that this will change in EF8 due to #10042

@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Jan 26, 2023
@ajcvickers ajcvickers added the closed-no-further-action The issue is closed and no further action is planned. label Jan 26, 2023
@luca-domenichini
Copy link
Author

@ajcvickers from what I have read in #10042, I understand that EF8 will be able to lazy fetch navigations starting from an untracked entity. Does it means that the DbContext will populate the IsLoaded property too?
Thanks very much for your support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported
Projects
None yet
Development

No branches or pull requests

2 participants