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

+2


source to share


3 answers


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 ...

+2


source


Sure.



You just need to declare an additional collection type property (for example, "map") on your User class, set its lazy attribute to false, and set its where attribute to the required SQL where clause.

-1


source


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.

-2


source







All Articles