Skip to content

Make lazy-loading work without direct field access #13084

Description

@bigworld12

Currently lazy loading proxies will look for fields no matter what, this hinders libraries with custom properties to work (e.g. Catel ), at least can lazy loading adapt to the already existing modelBuilder.UsePropertyAccessMode method ?

=================

EF Core version: 2.1.2
Database Provider: Sqlite
Operating system: Win10 x64
IDE: Visual Studio 2017 15.8.1

Activity

  1. ajcvickers commented on Aug 23, 2018

    @ajcvickers
    Contributor

    @bigworld12 EF writing directly to fields is currently required for lazy-loading to work. Can you show some examples of properties for which this is causing issues?

  2. bigworld12 commented on Aug 23, 2018

    @bigworld12
    Author

    @ajcvickers
    for example in Catel.Core which uses dependency-property-like properties
    a typical property in the model is defined like this

    // <summary>
    /// Gets or sets the name.
    /// </summary>
    public string Name
    {
        get { return GetValue<string>(NameProperty); }
        set { SetValue(NameProperty, value); }
    }
    
    /// <summary>
    /// Register the Name property so it is known in the class.
    /// </summary>
    public static readonly PropertyData NameProperty = RegisterProperty("Name", typeof(string), string.Empty);
    

    so you don't have direct access to the backing field, which adds features like (notification, saving and resetting object state, validation, etc..)
    so EntityFrameworkCore will not work with these types of properties as it's only looking for fields, not the access mode defined in modelBuilder.UsePropertyAccessMode

    i did some searching and probably that's where problems happen
    https://github.com/aspnet/EntityFrameworkCore/blob/release/2.2/src/EFCore.Proxies/Proxies/Internal/ProxyBindingRewriter.cs#L118

  3. ajcvickers commented on Aug 28, 2018

    @ajcvickers
    Contributor

    We discussed this in triage, and decided that we can support this through #2968. Keeping this issue open to track configuration of lazy-loading with this mechanism once implemented.

  4. added this to the Backlog milestone on Aug 28, 2018
  5. changed the title [-]Lazy Loading proxies use fields even though UsePropertyAccessMode is set to PropertyAccessMode.Property[/-] [+]Make lazy-loading work without direct field access[/+] on Aug 28, 2018
  6. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions