tags:

views:

247

answers:

1

I want to keep an entity, being configured by the user on several pages, in Session. This entity is loaded with NHibernate, with some of its properties/collections lazy-loaded. Say:

  • Session["order"] = new Order(productRepository.Get(id))
  • on some next page, get Session["order"] and now work with it

but, at this time order is OK but its Product (and nested stuff) is broken since they're lazy-loaded in different session.

Is it possible to tell NHibernate that I want to eager-load my transient order's properties to the deepest level? Or, the only solution will be to eager-load at the time of productRepository.Get(id) ? Like, Session.LoadNestedProperties(order, Eager);

Update: http://www.ribbing.net/index.php?option=com%5Fcontent&task=view&id=35&Itemid=1 seems to solve the issue. However I'm not sure that reflection is great...

A: 

Have a look here. It is the answer for Hibernate and not HNibernate but the result should be the same.

Henrik
It doesn't work for nested properties. If I have Order with Items, where each Item has Products, where each Product has Group (not collection but entity), and also Item has Shipping (collection or entity)... do I code loading of all of them manually? With 10 SetFetchMode()s?Another issue, is that my root entity is transient. I can't load it yet. I just want to load its properties.
queen3
I meant, it doesn't work recursively.
queen3