Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 6,026 | Comments: 44,842

filter by tags archive

NHibernate Tidbits: Serializing ICriteria

time to read 1 min | 187 words

Quite a few parts of NHibernate are serializable. ISession and ICriteria are of particular interest to this post. Serializing the session (neccesiate that the entities are serializable, of course) is very useful for the Session-pre-conversation mode. But it is the criteria that I would like to talk about right now.

Criteria in NHibernate is the OO interface for making queries. So, why is it important that it is serializable? Well, it opens up some interesting scenarios. Saved searches or reports are just one of many. I have used similar functionality in the past to build a rule engine, where saved criteria where the basis of selecting what a rule should process.

The only problem with that is that you usually want to display the query to the user. I have recently added inspection capabilities to the criteria, but they are focused more on infrastructure stuff rather than ease of extraction for the UI. For those cases, you might want to add a way or the UI to restore itself to the appropriate state for the selected search.


Pete w

I've actually used this one in the past.


You have a SalesReport that includes different types of SalesItems. How do you find the different SalesItems relevant to a SalesReport?

The simplest way, in my anecdote, was to serialize the SalesItem criteria as a property of the SalesReport.

No complaints from the client on that one, so everyone seems to be happy with this one :)

Comment preview

Comments have been closed on this topic.


No future posts left, oh my!


  1. Technical observations from my wife (3):
    13 Nov 2015 - Production issues
  2. Production postmortem (13):
    13 Nov 2015 - The case of the “it is slow on that machine (only)”
  3. Speaking (5):
    09 Nov 2015 - Community talk in Kiev, Ukraine–What does it take to be a good developer
  4. Find the bug (5):
    11 Sep 2015 - The concurrent memory buster
  5. Buffer allocation strategies (3):
    09 Sep 2015 - Bad usage patterns
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats