-
Notifications
You must be signed in to change notification settings - Fork 936
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
Add support for fetching an individual lazy property with hql and linq provider #1922
Add support for fetching an individual lazy property with hql and linq provider #1922
Conversation
I recently looked into the lazy properties feature and so I think this can be implemented simpler. I think it can be started from how |
This PR alters the uninitialized field names that are then passed to create a nhibernate-core/src/NHibernate/Tuple/Entity/PocoEntityTuplizer.cs Lines 238 to 246 in 192f301
where in the current master all fields are flagged as uninitialized: nhibernate-core/src/NHibernate/Tuple/Entity/PocoEntityTuplizer.cs Lines 232 to 237 in fdac0d0
nhibernate-core/src/NHibernate/Intercept/AbstractFieldInterceptor.cs Lines 138 to 141 in ac39173
There is a lot files changed due to deprecating methods and half of the added files are test cases. |
Related to #1267. |
In the current state, there are still some scenarios that this PR currently does not cover:
For #1267 I've modified the There is also #1232 that is related to this PR as the logic to detect a component in Linq was done here, for which I have to add some tests to see if it works. I also noticed that currently if the entity contains a lazy property, all the properties are set with the default setter which uses reflection: nhibernate-core/src/NHibernate/Tuple/Entity/PocoEntityTuplizer.cs Lines 290 to 296 in ac39173
to make them more performant I will probably make a separate PR to resolve that. |
About 1., are the two queries done on the same session without evicting? In such case, the second query is supposed to yield the same instance than the first query, discarding its loaded data. So the second lazy-property fetch is likely to even be ignored. About 2., yes, it will load again the already fetched lazy properties when loading an unfetched one, as currently it only knows to lazy-load them all. I think it is acceptable. Maybe, for consistency with 1. behavior, should it just be adapted to ignore the re-loaded values when hydrating lazy-properties. Lazy attribute fetch group is an interesting feature, but I do not think it will cover the 2. case. It may just mitigate it in some cases. If it is considered to port them, I think it will deserve a dedicated PR. |
Yes, they are.
this PR modifies this behavior such that the loaded lazy properties will be updated, so both lazy properties will be lodaded after the two queries (of course we should update it only if it wasn't altered). I think that we should not discard its loading data as it can produce different results with the same query, for example:
the above query can produce different results when running on various databases, depending by the order the rows are retrieved. If the For the second point I think that it deserve a separate PR if we would like to change the current behavior as we would need to change the current |
With the latest commit the 2nd level cache is now updated if a new lazy property was fetched in a separate query (same session)
or in the same query that has two occurrences of the same entity with different fetches
But does not update it if the lazy property is accessed via the property getter (
I leaved this for a separate PR that will include the lazy attribute fetch group feature, but I can add it here if desired. The field interceptor was slightly modified in order to not trigger the lazy properties initialization when one of them is set:
this allows to update the lazy property without having to initialize all of them. This produces a side effect as we don't know if the set value is different from the one that is in the database, so an update will be triggered even if the value is the same. Also the update will ignore the
Also #1232 was solved in latest commit and Linq
|
No, it is better to not widen the scope of PRs.
I would rather have this in a separated PR. By the way, does updating to |
Ok, will do.
Yes it works because |
75982ff
to
04761c6
Compare
04761c6
to
13860d7
Compare
Rebased. |
@@ -1457,10 +1529,35 @@ public string PropertySelectFragment(string name, string suffix, bool allPropert | |||
int[] columnTableNumbers = SubclassColumnTableNumberClosure; | |||
string[] columnAliases = SubclassColumnAliasClosure; | |||
string[] columns = SubclassColumnClosure; | |||
HashSet<string> fetchColumnsAndFormulas = null; | |||
if (fetchProperties != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this cannot be simply fetchProperties?.Contains(name)
?
Syntax for fetching in hql
Individual lazy property:
All lazy properties (already working):
Syntax for fetching in linq
Individual lazy property:
All lazy properties: