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,128 | Comments: 45,548

filter by tags archive

StoryVerse (and very cool search technique)

time to read 2 min | 203 words

StoryVerse is an agile management web application, based on MonoRail & Active Record. The UI is very googlish in nature, and I really like it. Still very early in the project, but showing a lot of promise.

The way that the guys from LunaVerse are using the criteria objects had me scratching my head for a while, until I saw how it is used on the controller, then I had a "Wow! That is cool!" momemt.

Here is a sample:

public void SearchProject([DataBind("project")] ProjectSearchCriteria projectSearchCriteria)
  PropertyBag["projects"] = Project.FindAll( projectSearchCriteria.ToDetachedCriteria() );

You really need to check out the code in order to appriciate it. It is like placing a lot of domino pieces and watching them all fall into places, no extra work required. Here is one technique that I am so going to take advantage of next time I am going to write a search screen.


Tim Haines

Sounds like a great thing to link to from http://using.castleproject.org.

Ayende Rahien

It is a wiki, create an account and do it :-)

Roy Osherove

Care to elaborate to the coolness of this?

Not everyone understands what's going on in that piece of code.


Ayende Rahien

ProjectSearchCriteria is a class that has properties such as From, To, UserName, etc.

The coolness factor is that they are filled automagically by the [DataBind] property.

Since the properties setter build the criteria directly, this means that the whole complexity of the search form was reduce to a very small problem of just executing the criteria.

A very easy way to handle the problem

Fábio Batista

Way cool! I already used [DataBind] to fill some DTO, but never though on using it to fill a clever object that can generate a Criteria ;)

Very good SOC.

Tim Scott

First, thanks for the kind comments.

This pattern has been evolving. It began in a prior (non ActiveRecord) project. In that version we passed our custom criteria object into a repository method which then built HQL and passed it on to our data gateway.

The newer approach, reflected in StoryVerse, is nice for a couple of reasons. First, it uses strongly typed ICriteria instead of HQL. Also, it's nice to encapsulate the creation of Nhib criteria inside the custom criteria class. Thus the class could be easily extended to support other gateway implementations. For example, you could add a ToSql() method or perhaps something like ToLinqQuery() ???

Recently we have improved on this pattern by coupling custom criteria objects with Dto objects. We added a property to the criteria class, ReturnType, with values of "Entity" and "Dto." When the return type is Dto, we use AliasToBeanResultTransformer to automagically return a list of Dtos instead of root entities.

I was planning to write an article soon that demonstates this newest rendition of the pattern. However, we're having a problem that appears to be an NHibernate bug, described here: http://forum.hibernate.org/viewtopic.php?t=973951&highlight=alias

Comment preview

Comments have been closed on this topic.


  1. The low level interview question - 9 hours from now
  2. The worker pattern - 3 days from now

There are posts all the way to May 30, 2016


  1. The design of RavenDB 4.0 (14):
    26 May 2016 - The client side
  2. RavenDB 3.5 whirl wind tour (14):
    25 May 2016 - Got anything to declare, ya smuggler?
  3. Tasks for the new comer (2):
    15 Apr 2016 - Quartz.NET with RavenDB
  4. Code through the looking glass (5):
    18 Mar 2016 - And a linear search to rule them
  5. Find the bug (8):
    29 Feb 2016 - When you can't rely on your own identity
View all series



Main feed Feed Stats
Comments feed   Comments Feed Stats