views:

489

answers:

3

Hi,

I am curious about what methods do you use for complex searching with NHibernate ?

I am using Ayende's

What is yours ? Thanks for your advices and answers.

+1  A: 

If we have a complex dynamic search, we will usually construct a SearchParameter object and then pass that into a method that will build our criteria for us.

For example, if we were searching for a person we might have a search object that looks like this:

public class PersonSearchParameters
{
    public string FirstName {get; set;}
    public string LastName {get; set;}

    public ICriteria GetSearchCriteria()
    {
        DetachedCriteria query = DetachedCriteria.For(typeof (Person));
        //Add query parameters
        Return query;
    }
}

Then for each type of search, we'll be able to create the single criteria from the class, or we could have multple search parameter classes and chain them together

lomaxx
That's the same i useThank you
Barbaros Alp
+1  A: 

We use HQL, but we're still trying to wrap our heads around the Criteria API for complex queries. We have to manage a lot of duplication when using HQL.

orip
I am not a master at HQL at all but it seems that building complex queries with DetachedCriteria looks easier.Thanks for your answer
Barbaros Alp
+1  A: 

hi there

I use pretty much Ayende's too jsut a bit more complex, what do you want to do that you cant do with that?

Basically what we added is that we have an interface where we define all the fields where we want to search and we call this when we are about to make the search which means that we can easily change what we are searching for.

Also we are using Active Record in the project ( on top of Hibernate) and tis pretty cool, loads of tasks gets simplified , thou the lack of docs does hurt sometimes Cheer

Miau
the interface thing sounds great, could you please post some code here or somewhere might be my mail address
Barbaros Alp