Samuel Goldenbaum
Samuel Goldenbaum

Reputation: 18909

NHibernate - How to eager load entire object graph and then cache it along with all children and grandchildren

I am not understanding the following scenario. I have a situation where I need to load children and grandchildren along with an entity. I have specified that collections are lazyloaded, but eagerly fetch all rows using detached criteria and setfetchmode to eager. I have the following problem:

  1. NHibernate is taking very long to hydrate the objects - the actual queries run quickly though.
  2. I place the list of results into .net MemoryCacheManager object and seems that after a while the grandchildren seem to drop out the object and I get a lazyload exception.

How to I ensure that the entire graph returned by the results remains in tact in the MemoryCacheManager object? Does session.Evict help me?

Upvotes: 1

Views: 545

Answers (1)

Samuel Goldenbaum
Samuel Goldenbaum

Reputation: 18909

Ended up using QueryOver future queries and flattened the results into a DTO and ended up caching the DTO.

Upvotes: 1

Related Questions