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

Is virtual for lazy loading still needed? #3318

Closed
angelsix opened this issue Oct 4, 2015 · 8 comments
Closed

Is virtual for lazy loading still needed? #3318

angelsix opened this issue Oct 4, 2015 · 8 comments

Comments

@angelsix
Copy link

angelsix commented Oct 4, 2015

I ask because the UnicornStore demo doesnt set for example Product as virtual in CarlItem and OrderLine, yet it does .Include(i => i.Product) which wouldnt be needed if it wasn't virtual lazy loaded in the first place.

@angelsix
Copy link
Author

angelsix commented Oct 4, 2015

That's what I thought. If virtual is still needed then the sample code is misleading and or wrong or just superfluous as it calls .Include when a non virtual property will already be fully loaded

Sent from my Samsung Galaxy smartphone.

-------- Original message --------
From: Derek [email protected]
Date: 04/10/2015 20:39 (GMT+00:00)
To: aspnet/EntityFramework [email protected]
Cc: Luke Malpass [email protected]
Subject: Re: [EntityFramework] Is virtual for lazy loading still needed? (#3318)

This is an unofficial answer in the form of a question, but how would lazy loading be implemented without an overridden property?

Reply to this email directly or view it on GitHubhttps://github.com//issues/3318#issuecomment-145380507.

@divega
Copy link
Contributor

divega commented Oct 5, 2015

@angelsix EF7 does not lazy-load automatically through navigation properties so that does not play as a reason to make the properties virtual.

@angelsix
Copy link
Author

angelsix commented Oct 5, 2015

Ah ok. My understanding was if a single item isn't marked as virtual, it will fully load when you load the parent item. Only collections/lists didn't load automatically. So a Product would fully load, but an ICollection would not of.

Is my understanding wrong? I am sure in EF6 I had to mark single navigation properties on a class as virtual otherwise they got eager loaded when the parent object was loaded.

@divega
Copy link
Contributor

divega commented Oct 5, 2015

What you are describing sounds a bit like how things work in NHibernate: If you specify 'lazy = false' on a property, it will get eager loaded; collections default to 'lazy = true' and references default to 'lazy = false'.

In EF6 you make navigation properties virtual to enable the creation of proxy types in which we can embed the ability to lazy load. EF6 will never eager load anything automatically (you have to ask for it in the query), and if lazy loading is enabled it will work the same for collection and reference properties.

@divega
Copy link
Contributor

divega commented Oct 5, 2015

@rowanmiller do you know if we have anything in the documentation, feature list, roadmap or blog posts that mentions the status of lazy loading in EF7?

@rowanmiller
Copy link
Contributor

It's listed on our roadmap as a high priority feature but something we'll implement based on feedback https://github.com/aspnet/EntityFramework/wiki/Roadmap#high-priority-features

@applenele
Copy link

+1 for Lazy load

@yukozh
Copy link
Contributor

yukozh commented Oct 25, 2015

In the past. I have used the dynamic linq (https://github.com/mrKrizz/dynamic-linq) with lazy load. but in the ef7, without the lazy load, I cannot use the dynamic linq anymore. sad.
At the same time, we have to type more codes to solve circular reference.
I really hope it can come back.

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants