Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get a lazy IEnumerable from an NHibernate query using ICriteria?

I'm working with NHibernate and need to retrieve and process up to 2 million rows. Ideally, I could process each row - one at a time - without NHibernate loading all 2 million in memory at once (because, you know, that hurts).

I'd prefer to get an IEnumerable which would call the data reader iteratively for each read so I could process the data read - then discard it. By doing it this way I save a boatload of memory, and begin processing results far faster. I could also improve performance through multithreading and/or the use of PLinq.

Is this possible with NHibernate's ICriteria? Everything it returns seems to be IList, and fully loaded before handing the collection reference off. Why IList instead of IEnumerable?!

I don't mean "lazy" in the traditional sense that NHibernate uses with regards to loading child or parent objects. I want a lazy IEnumerable meaning someway of getting a IEnumerable from an ICriteria object. ICriteria only has a List() method which loads the results in an ArrayList.

like image 554
TheSoftwareJedi Avatar asked Dec 12 '08 14:12

TheSoftwareJedi


1 Answers

ICriteria doesn't have any methods that return an IEnumerable, but IQuery does.

like image 116
Mauricio Scheffer Avatar answered Oct 04 '22 20:10

Mauricio Scheffer