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

LazyLoadOnDisposedContextWarning thrown for eager-loaded entities (via Include)? #11931

Closed
vflame opened this issue May 8, 2018 · 3 comments
Closed

Comments

@vflame
Copy link

vflame commented May 8, 2018

Is it intended for LazyLoadOnDisposedContextWarning to be thrown when navigational properties are eagerly loaded with .Include()? I know that the warning can be suppressed but in this case, the navigation properties are not lazy-loaded.

The dbContext is registered with .UseLazyLoadingProxies() and the navigation property is accessed after the dbContext is disposed:

    //Parent class with virtual ChildNavigationProperty
    var items = context.ParentClass.Include(x => x.ChildNavigationProperty).ToList();
    context.Dispose();

   //exception thrown here
    Console.WriteLine(item.First().ChildNavigationProperty); 

On a side note, this exception should also not be thrown for any entities queried using a context with context.ChangeTracker.LazyLoadingEnabled = false; since the navigation properties would just be null.

@ajcvickers
Copy link
Member

Note for triage: the issue here is that once the context is disposed it cannot\should not be used, and this includes using it to determine whether or not a navigation property is loaded. This can be improved as part of #10042 by storing the loaded state in the proxy such that the context does not need to be asked again. However, we're not doing this for 2.1 and I propose we leave the current behavior as is, especially since the warning-error can be turned off.

@ajcvickers
Copy link
Member

/cc @divega

@divega
Copy link
Contributor

divega commented May 10, 2018

Closing as dupe of #10042.

@divega divega closed this as completed May 10, 2018
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants