NHibernate - Retrieving Lots of Data Becomes Exponentially Slow

Posted by nfplee on Stack Overflow See other posts from Stack Overflow or by nfplee
Published on 2010-12-22T17:20:45Z Indexed on 2010/12/22 21:54 UTC
Read the original article Hit count: 209

Filed under:

Hi, I have an issue when I retrieve lots of data in NHibernate (such as when producing a report) the page becomes exponentially slower the more data it has to retrieve. I found the following article:

http://nhforge.org/blogs/nhibernate/archive/2008/10/30/bulk-data-operations-with-nhibernate-s-stateless-sessions.aspx

It explains how doing bulk data operations in NHibernate is slow since the first level cache grows too large and how you should use the IStatelessSession instead. The trouble I have is that I don't wish to tie my application to NHibernate so I've added a wrapper around ISession. I then use Linq as my query mechanism but IStatelessSession does not support Linq (it may do in NHibernate 3 but the Linq provider is not stable as it stands at the moment).

I then read that you could do a clear after so many iterations to clear out the first level cache. The problem now is that you can't use lazy loading. The linq provider doesn't allow you to override the mapping defined (or eagerly fetch the additional data) so whenever I grab data which is lazy loaded after I have cleared the session an exception is thrown.

I'm completely lost on what do now. I like the ease of producing reports with linq but the limitations of the inbuilt linq provider in NHibernate seem to be holding me back.

I'd really appreciate it if someone could show me an alternative approach. Thanks

© Stack Overflow or respective owner

Related posts about nhibernate