EntityFramework.Docs icon indicating copy to clipboard operation
EntityFramework.Docs copied to clipboard

Clarify the basics of proxies

Open pav1 opened this issue 6 years ago • 6 comments

No mention of these.. now I need to go figure


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

pav1 avatar Jan 06 '19 23:01 pav1

@pav1 can you please be more specific?

divega avatar Jan 07 '19 22:01 divega

I think they are saying "virtual" isn't mentioned anywhere and that's pretty common in EF so it should likely be explained how it's being used in regards to Entity Framework. https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/virtual doesn't really make sense in the context of Entity Framework.

KSib avatar Jan 31 '19 16:01 KSib

I believe "virtual" in the model class is used for lazy loading @KSib

TruthWithLove avatar Feb 26 '19 05:02 TruthWithLove

@ZeroPKI Right, but where is that in the documentation that OP posted? That's the problem. I think there's a lot of confusion here for some reason.

KSib avatar Feb 26 '19 14:02 KSib

EF "Overrides" classes with a "proxy" class, which is nothing else but a subclass that inherits from your data class. To be able to intercept/modify requests, by example, when using lazy loading, it needs to override properties in an OOP way, and doing so adds code to the get; set; of the properties to check values, do lazy loading and assign primary keys returned by the database. If you don't use virtual, EF has no way do its magic as cannot intercept the requests.

SoyYop avatar Mar 03 '19 05:03 SoyYop

See also discussion in https://github.com/dotnet/efcore/issues/19035

ajcvickers avatar Jan 23 '20 16:01 ajcvickers