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

Make lazy-loading work without direct field access #13084

Open
bigworld12 opened this issue Aug 22, 2018 · 3 comments
Open

Make lazy-loading work without direct field access #13084

bigworld12 opened this issue Aug 22, 2018 · 3 comments

Comments

@bigworld12
Copy link

bigworld12 commented Aug 22, 2018

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

@ajcvickers
Copy link
Contributor

ajcvickers commented Aug 23, 2018

@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?

@bigworld12
Copy link
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

@ajcvickers
Copy link
Contributor

ajcvickers commented Aug 28, 2018

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.

@ajcvickers ajcvickers added this to the Backlog milestone Aug 28, 2018
@ajcvickers ajcvickers changed the title Lazy Loading proxies use fields even though UsePropertyAccessMode is set to PropertyAccessMode.Property Make lazy-loading work without direct field access Aug 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants