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

Lazy Loaded Proxies (more than just lazy loaded navigation properties) #8480

Open
Tracked by #22954
Wain123 opened this issue May 16, 2017 · 4 comments
Open
Tracked by #22954

Comments

@Wain123
Copy link

Wain123 commented May 16, 2017

Since lazy loaded navigation properties are planned for a future version of EF Core, I'll consider them as a given here. I am looking for a feature similar to NHibernate's lazy loaded proxies. To be more specific:

I often want to set or read navigation properties and compare entities for equality. Example:
if(post1.Blog == post2.Blog)
In the above line, post1 and post2 are already loaded, but post1.Blog and post2.Blog might not be. I want to be able to do the comparison above without loading post1.Blog and post2.Blog from the database - essentially, I want to compare the foreign keys, by using a Blog entity as a "proxy".

Here's another example:
Blog b = post1.Blog;
post1.Blog may or may not have been loaded previously. If it was, b is a normal Blog. Otherwise, b is a proxy that has a primary key value but no property values.
post2.Blog = b;
Doesn't require DB access.
string s = b.URL;
If b isn't loaded yet, EF automatically gets b's property values from the DB, since one of them was requested.

The following workarounds are not satisfactory:

  • Splitting the Blog table into two entities (or, since table splitting isn't in EF Core yet, into two tables and two entities) - one that has only the primary key and one that has the properties. I am unable to hide this hack in such a way that I can program with it as if it were a single entity.
  • Letting the business logic know whether an entity is loaded or not. That would complicate my business logic. Also, primary keys and foreign keys are a DB concept that doesn't belong in business logic in the first place.
@ajcvickers ajcvickers added this to the Backlog milestone May 17, 2017
@giggio
Copy link

giggio commented Aug 15, 2017

This is one of those things that should just work and that enable a good code writing experience. The ORM is almost invisible. This is a must. Good one!

@Wain123
Copy link
Author

Wain123 commented May 1, 2018

Maybe duplicate of #1387

@ajcvickers
Copy link
Contributor

@Wain123 #1387 is a completely different feature. This feature is about not lazy-loading an entity when not needed; #1387 is about lazy-loading non-navigation properties.

@szpght
Copy link

szpght commented Aug 22, 2018

This can be based on #997

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

5 participants