-
Notifications
You must be signed in to change notification settings - Fork 934
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
QueryOver with Select and Fetch not working correctly #2698
Comments
It's by design - projections completely overwrite SELECT statement. So all fetch requests won't be included in SELECT. Use the following query to fetch root entity with lazy properties + Items collection: session.QueryOver<EntityA>()
.Fetch(SelectMode.FetchLazyProperties, x => x)
.Fetch(SelectMode.Fetch, x => x.Items)
.TransformUsing(Transformers.DistinctRootEntity)
.SingleOrDefault(); |
I can understand that this is by design but in this case, why eager loading from mapping works in Select? For me this is not very consistent behaviour. I would rather prefer opposite approach: if we overwrite Select that eager loading from mapping doesn't work (by design) but if you force eager in your query by Fetch() method that this fetch will work. |
Are you sure it's loaded in single query? I think your collection is loaded in separate query in this case. Also just in case |
All fetches are loaded in separate SQL queries (query per object type). But from NHibernate user point of view this is done automatically and in one NHibernate query.
As I mentioned, my test code is simple to show the problem I've encountered. In my real query I have many references and collections I need to fetch. To illustrate my real case: imaging that in my class Entity A I have a few collections like Items, my EntityB has also collection like Items and a few references and so on. |
Then answer is simple - it has nothing to do with Select. Mapping eager loading works for entity no matter how it's loaded via Fetches for projections are not supported. |
Ok, thanks for the answer |
I have found that sometimes fetching lazy properties doesn't work and property is still lazy. I've prepared a test code to reproduce this issue:
In this example if we have a QueryOver with a Select, then there is no way to eager fetch properties. Only way to force Items collection to be eager loaded is to change a mapping and set NoLazy instead of Extra.
If you need more info, please let me know
The text was updated successfully, but these errors were encountered: