Partial lazy loading
I have a single User object that can have multiple posts.
Example:
Load user with lazy loading posts IList<User> users = User.LoadAll()
Then I only want to read "half" users[2].Posts[3]
(only get the attributes I want, not all from this post object), is it possible to do this?
(Note, I don't want to use View).
Edit: Can anyone give me a simple code example please? I tried to find it with no success. Thanks to
source to share
If I understand your question well - you want to get an object - a message in your case - but only some of its properties - eg. Post.Annotation and not Post.Content, which are strings.
This is not possible at the moment. Each object retrieved from the database will have all its properties, which are not associated with any relationship or collection.
You can do a workaround:
-
by turning the biggish properties into a separate object and then many-to-one mapping and using lazy loading
-
by creating your own query, be it HQL or criteria with projections (mostly just a few columns). However, this will not return a complete object.
I hope I understood your question correctly ...
source to share
Yes it is possible.
When NHibernate restores an object from the database, it can also restore all members of the object, creating the entire object graph. This is called cascading, it is the property of the association defined in your mappings file and the sound of things you don't want. See the documentation for details.
source to share