Is virtual for lazy loading still needed?
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.
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/aspnet/EntityFramework/issues/3318#issuecomment-145380507.
@angelsix EF7 does not lazy-load automatically through navigation properties so that does not play as a reason to make the properties virtual.
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
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.
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.
@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?
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
+1 for Lazy load
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.