November 9, 2007

NHibernate DetachedCriteria

are funky…. 

No idea if this is normal behavior, but I am using a ‘DetachedCriteria’ in a search object.  I want to generate a page of search results, so I need both the total rows returned as well as the slice of the data for this page.  So, generate a DetachedCriteria for the where clause, use a ScalarProjectionQuery to get the total count, and then a SlicedFindAll to get the page.  I DON”T THINK SO!  Using the DetachedCriteria in one query seems to mess it up for the next query, so I end up making to copies of the where clause, one per query, and it works fine.  WTF!  Bug or feature?  I don’t know, just beware if you are doing the same and getting funky errors.