Skip to content

Clarify that lazy-loading cannot be opted-out of by making a property non-virtual #1607

Open
@gaazkam

Description

@gaazkam

> EF Core will then enable lazy loading for any navigation property that can be overridden--that is, it must be virtual and on a class that can be inherited from.

The above statement from this docu page seems misleading to me: it hints that navigation properties can be virtual or not, and if they're not virtual, they will simply not be lazy-loaded.

Instead it would seem that if lazy loading is enabled EVERY navigation property on EVERY model of such a db context has to be virtual, because else we will see exceptions being thrown on app startup by .migrate()!

Another: There seem to be some requirements about constructors in models. Queries that used to be working before enabling lazy loading are now throwing because "Can not instatiate proxy of class Blah.Blah Could not find a constructor that would match given arguments."

Because of all of the above it would seem that enabling lazy loading requires some special preparations, far surpassing installing the NuGet package this docu page mentions and adding .UseLazyLoadingProxies() to startup.cs.

I can not see these requirements documented here. I'd suggest mentioning them on this page and either documenting them extensively or linking to a separate docu page where they are described.


Document Details

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions